Why will this code will work for a smaller multiple like 10 but time out for anything over 13?
Can this code be refactored to work for larger numbers?
(p.s. I have an alternate solution but wanted to see if this code could be fixed to work for more multiples.)
#2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
multiple = 10
y = multiple
hash = Hash.new(0)
loop do
if hash.has_value?(multiple) || y == 0
break
end
for x in 1..multiple do
if y % x == 0
hash[y] += 1
end
end
y += multiple
end
puts "Smallest number = #{y - multiple}"
hash.has_value?(multiple)