25 lines
630 B
Ruby
25 lines
630 B
Ruby
require_relative 'euler'
|
|
require 'prime'
|
|
|
|
def factorization_of_integer_divisible_by_all_integers_up_to(n)
|
|
{}.tap do |factorization|
|
|
(2..n).map do |i|
|
|
Prime.prime_division(i).map do |factor|
|
|
factorization[factor.first] = factor.last if (!factorization.include?(factor.first) || (factor.last > factorization[factor.first]))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
def factors_to_int(factorization)
|
|
[].tap do |result|
|
|
factorization.each do |prime, exponent|
|
|
result << prime ** exponent
|
|
end
|
|
end.inject(:*)
|
|
end
|
|
|
|
def solution
|
|
factors_to_int(factorization_of_integer_divisible_by_all_integers_up_to(20))
|
|
end
|