Created
May 18, 2012 12:35
-
-
Save just3ws/2725052 to your computer and use it in GitHub Desktop.
1089
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some return 198, not sure why.