Я ищу подробное объяснение того, как это решение работает. Он находит наименьшее положительное число, которое можно разделить на все числа от 1 до 20 без остатка.Пояснение для Ruby Solution к «Наименьшее положительное число, делящееся»
test = 20
divisor = 0
while true
# Don't check factors from 1-10, since all included in 11-20. Plus check backwards from 20 down, to save time.
20.downto(11) do |d|
divisor = d
# puts "test = #{test}, d = #{d}"
break if test % d != 0
end
if divisor == 11 && test % divisor == 0
puts "Answer = #{test}"
exit
end
test += 20 # only need to check multiples of 20
end
В частности, я не знаю, где в коде цифры умножаются, что дает 232,792,560.
Мне нравится @ Ответ Брайтана [здесь] (http://codereview.stackexchange.com/questions/67938/project-euler-5-lowest-multiple-of-1-through-20). –
http://meta.stackoverflow.com/questions/253894/how-to-handle-explain-how-this-code-dump-works-questions/253896#comment17104_253896 –