Problem 52

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.

x = 10000 loop do break if [x,2*x,3*x,4*x,5*x,6*x].collect{|i| i.to_s.split('').sort}.uniq.size == 1 x += 1 end p x

found = false d = 0 while !found d += 1 s = [d, d*2, d*3, d*4, d*5, d*6].map {|i| i.to_s.split('').sort}.uniq.size found = true if s == 1 end p d
=> 142857

x=1;x+=1 until (1..6).map{|i|(i*x).to_s.split('').sort}.uniq.size==1;x