Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [REBOL] The magic of numbers
Index -> Programming, General Programming -> Functional Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
btiffin




PostPosted: Wed Jul 02, 2008 12:01 am   Post subject: [REBOL] The magic of numbers

Pull up REBOL and evaluate this expression

code:
n: ask "any 3 'different' digits "  print add  to integer! probe p: join copy/part "000" subtract 3 length? r: form abs subtract  to integer! reverse n to integer! reverse n  r to integer! reverse p

It rarely matters what number you input (as long as it is three different digits - more specifically not a palindromic number). So, 001 is actually ok, but not 101 or 888 for instance.

Here is your answer
Spoiler:
1089


Challenge: Write a one liner in your favourite language to show off the same magic number trick.

Cheers
P.S. just in case you can't read REBOL yet (and to be fair to wtd, this one is a little obfuscated). Take any 3 digit value, take the absolute value of that number minus the reverse of that number (pad with zeroes to fill it out to 3 digits) and call it first result. Take the first result and add it to the reverse of the first result and you get the same value every time. Example 123 - 321 + reverse of the absolute value of that result
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, General Programming -> Functional Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: