Mayank S
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
>> 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
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
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 ;-)
cjjclifford's answer is the right one though ;-)
ASKER
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\u00 70\u0075\u 0062\u006c \u0069\u00 63\u0020\u 0063\u006c \u0061\u00 73\u0073\u 0020\u0050 \u0075\u00 7a\u007a\u 006c\u0065 \u007b\u00 70\u0075\u 0062\u006c \u0069\u00 63\u0020\u 0073\u0074 \u0061\u00 74\u0069\u 0063\u0020 \u0076\u00 6f\u0069\u 0064\u0020 \u006d\u00 61\u0069\u 006e\u0028 \u0053\u00 74\u0072\u 0069\u006e \u0067\u00 5b\u005d\u 0020\u0061 \u0072\u00 67\u0073\u 0029\u007b \u0066\u00 6f\u0072\u 0028\u0069 \u006e\u00 74\u0020\u 0069\u003d \u0030\u00 3b\u0069\u 003c\u0049 \u006e\u00 74\u0065\u 0067\u0065 \u0072\u00 2e\u0070\u 0061\u0072 \u0073\u00 65\u0049\u 006e\u0074 \u0028\u00 61\u0072\u 0067\u0073 \u005b\u00 30\u005d\u 0029\u003b \u0069\u00 2b\u002b\u 002c\u0053 \u0079\u00 73\u0074\u 0065\u006d \u002e\u00 6f\u0075\u 0074\u002e \u0070\u00 72\u0069\u 006e\u0074 \u0028\u00 69\u002b\u 0022\u0020 \u0022\u00 29\u0029\u 003b\u007d \u007d\u00 2f\u002a') .encode()
*/public class Puzzle{public static void main(String[] args){for(int i=0;i<Integer.parseInt(arg s[0]);i++, System.out .print(i+" "));}}/*
(note I stripped off the comments added to the unicode before running it through Python!)
print unicode(u'\u002a\u002f\u00
*/public class Puzzle{public static void main(String[] args){for(int i=0;i<Integer.parseInt(arg
(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 ;-)
neat! :-D
I keep meaning to learn Python... especially now I have it on my phone ;-)
>> have it on my phone
useful (!)
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
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!
>> (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? :-)
ASKER
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 ;-)
>> Muhahahah!
The first time Tim didn't laugh with a he he he ;-)
ASKER
>> Can my Java program call another program? :-)
Yes, it can. Ask it in your question and we would be glad to answer ;-)
Yes, it can. Ask it in your question and we would be glad to answer ;-)
:-D
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!)
ASKER
He he.... yeah, that's a good point ;-)
decompiled to a for() loop :-)