Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
[REBOL] The magic of numbers
Author Message
btiffin

Posted: 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.

 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