Created
March 11, 2012 03:07
-
-
Save larryv/2014808 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby1.9 | |
# Project Euler, Problem 52 | |
# | |
# It can be seen that the number 125874, and its double, 251748, contain | |
# exactly the same digits, but in a different order. | |
# | |
# Find the smallest positive integer x such that 2x, 3x, 4x, 5x, and 6x | |
# contain the same digits. | |
# | |
# Lawrence Velazquez | |
class Integer | |
def same_digits?(n) | |
self.to_s.split(//).sort == n.to_s.split(//).sort | |
end | |
end | |
n = 1 | |
n = n.next until (Array.new(5) {|i| n * (i + 2)}).all? {|x| x.same_digits?(n)} | |
puts n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment