Programing Puzzles

JAnderson ask at me.com
Wed Aug 6 23:54:43 PDT 2008


BCS wrote:
> Reply to Koroskin,
> 
>> On Thu, 07 Aug 2008 01:50:56 +0400, Wyverex <wyverex.cypher at gmail.com>
>> 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.
>>>
>> // 0 is considered a power of two here
>> bool isPowerOfTwo(int i) {
>> return (i & (i-1) == 0);
>> }
> 
> isPowerOfTwo(int.min);
> 
> 
> 0b10000000  == byte.min
> 0b01111111  == byte.min -1
> 
> 0b00000000
> 
> 



What are you trying to say?  I imagine your validating Koroskin solution.

10000000  == byte.min
01111111  == byte.min - 1
=
00000000  == is power of 2

-Joel


More information about the Digitalmars-d-learn mailing list