Skip to content

Instantly share code, notes, and snippets.

@just3ws
Created May 18, 2012 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save just3ws/2725052 to your computer and use it in GitHub Desktop.
Save just3ws/2725052 to your computer and use it in GitHub Desktop.
1089
# 1) Take any 3 digit number, But the first and third number Cannot be the same.
# 2) reverse the order and subtract
# 3) reverse the answer and then add it
"1234567890"
.split(//)
.map {|i| i.to_i }
.permutation(3)
.to_a
.map {|n| [n, n.reverse] }
.map {|x| [x.first.join, x.last.join].sort.reverse.reduce {|y,z| y.to_i - z.to_i } }
.map {|x| [x, x.to_s.reverse.to_i].reduce {|y,z| y + z } }
@just3ws
Copy link
Author

just3ws commented May 18, 2012

Some return 198, not sure why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment