Link to home
Start Free TrialLog in
Avatar of Mayank S
Mayank SFlag for India

asked on

Puzzle :)

Hi folks,

There haven't been enough Q's on EE since last day, so I thought that I might as well post my own to take some of your time ;-)

This is a good puzzle which I found on the Net.... how would you print a sequence of numbers 1  2  3 .... n without using any conditional operators, any other operators like >, ==, etc, no loops like for, while, do-while or any conditional statements like if-else.

(Recursion is allowed.)

- Mayank.
ASKER CERTIFIED SOLUTION
Avatar of cjjclifford
cjjclifford

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cjjclifford
cjjclifford

ah, unicode...
decompiled to a for() loop :-)
hi timyates,
 
yours is a bit different. did you convert all your pogram into hex code and dumped here ???

anyway its good, i never knew that i could write a program like this also.
>>  ah, unicode...
>> decompiled to a for() loop :-)

;-)  shhhh! ;-)

hehehe

>> yours is a bit different. did you convert all your pogram into hex code

Yeah, wrote the program, converted it to unicode chars, and added a comment round it ;-)

That way it passes the compiler, which then converts it into the proper java code just before it gets compiler ;-)

Woo!

hehehe
Avatar of Mayank S

ASKER

Tim, that really impressed me ;-) let me check that out :)
>> That way it passes the compiler, which then converts it into the proper java code just before it gets compiler ;-)

should read:

That way it passes the parser, which then converts it into the proper java code just before it gets compiled ;-)

hehehe
>>  Tim, that really impressed me ;-) let me check that out :)

cjjclifford's answer is the right one though ;-)
I know that ;-) and still don't know how your code does it (maybe it uses conditional operators ;)) he he.... lemme run it.
hee hee ;-)
compile it, then decompile it with jad ;-)
or you can use python:

print unicode(u'\u002a\u002f\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0063\u006c\u0061\u0073\u0073\u0020\u0050\u0075\u007a\u007a\u006c\u0065\u007b\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0076\u006f\u0069\u0064\u0020\u006d\u0061\u0069\u006e\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u005b\u005d\u0020\u0061\u0072\u0067\u0073\u0029\u007b\u0066\u006f\u0072\u0028\u0069\u006e\u0074\u0020\u0069\u003d\u0030\u003b\u0069\u003c\u0049\u006e\u0074\u0065\u0067\u0065\u0072\u002e\u0070\u0061\u0072\u0073\u0065\u0049\u006e\u0074\u0028\u0061\u0072\u0067\u0073\u005b\u0030\u005d\u0029\u003b\u0069\u002b\u002b\u002c\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u0028\u0069\u002b\u0022\u0020\u0022\u0029\u0029\u003b\u007d\u007d\u002f\u002a').encode()
*/public class Puzzle{public static void main(String[] args){for(int i=0;i<Integer.parseInt(args[0]);i++,System.out.print(i+" "));}}/*

(note I stripped off the comments added to the unicode before running it through Python!)
>>  or you can use python:

neat! :-D

I keep meaning to learn Python...  especially now I have it on my phone ;-)
>> have it on my phone

useful (!)
Hehehe, not really, but you can access the bluetooth stack, and have sms control...

I've almost got a "Countdown numbers game" solver working too ;-)

Ahhh...  I'm such a nerd...

;-) hehehe
if you have access to open URLs (import urllib) you could even write a experts-exchange program :-)
monitoring program is what I meant, obviously :-) (Might cost you a bit on the data rates!!!)
Hee hee, yeah :-)

>> (Might cost you a bit on the data rates!!!)

That's how they get you :-(

Maybe time to work out how to route my phone's net connection via my home broadband over bluetooth...

Then the world of crazy python web parsing will be mine!!  Muhahahah!
 Can my Java program call another program? :-)
Well, this one definitely turned out to be more interesting than I had initially anticipated ;-)

>> Muhahahah!

The first time Tim didn't laugh with a he he he ;-)
>> Can my Java program call another program? :-)

Yes, it can. Ask it in your question and we would be glad to answer ;-)
 I mean the Java program call another program that print 1, 2 ... n. Isn't it a solutions? :-)
Oooh.. that's a good point! ;-)
you've still got to check for termination :-) (without conditionals, etc!)
He he.... yeah, that's a good point ;-)