Programing Puzzles

Koroskin Denis 2korden at gmail.com
Thu Aug 7 07:30:50 PDT 2008


On Thu, 07 Aug 2008 10:50:25 +0400, JAnderson <ask at me.com> wrote:

> Wyverex wrote:
>> just some fun little programming puzzles I found around online...
>>    Write a "Hello World" program in 'C' without using a semicolon.
>> (Note: #include in C doesn't need a semicolon but import does)
>>    Problem #1 Write a "Hello World" program in D with only a semicolon  
>> on import statement.
>>  Problem #2 Test if an int is even or odd without looping or if  
>> statement (Cant use: do, while, for, foreach, if).
>>  Problem #3 Write a program without using any loop (if, for, while etc)  
>> to print numbers from 1 to 100 and 100 to 1;
>>  Problem #4 Find if the given number is a power of 2.
>>    Post Solutions to this root, comments to someones solution in that  
>> thread.
>
> These are pretty standard interview questions. Although I don't  
> personally like to ask these sort of questions because they are often  
> about knowing a "trick" which you an easily lookup.  The can be fun to  
> figure out though.
>
> Here's another common one:
>
> | Write a bitcount for a 32-bit number.
>
> And a little more challenging:
>
> | Write a bitcount for a 32-bit number that is less then 15 operations  
> without using a lookup table.
>
> | Can you do that in 12 or less?
>
> -Joel

I know the solution for 15 operations, but it is impossible to come up  
with solution quickly. Besides, it requires 64 bit arithmetic support.


More information about the Digitalmars-d-learn mailing list