Project Euler Problem 52 Solution

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.

My solution in Ruby:

i = 1;
answer = nil;

while answer == nil
  i += 1
  x = i * 2
  base =
  matchbase = true
  for t in 3..6
    break if matchbase == false
    x = i * t
    digits =
    digits.each { |d| matchbase = false if base.index(d) == nil }
  answer = i if matchbase == true
puts "Answer: #{answer}"

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.