Skip to content

Instantly share code, notes, and snippets.

@larryv
Created March 11, 2012 03:07
Show Gist options
  • Save larryv/2014808 to your computer and use it in GitHub Desktop.
Save larryv/2014808 to your computer and use it in GitHub Desktop.
#!/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