2014-11-20 19:38:31 +00:00
|
|
|
require_relative 'euler'
|
|
|
|
|
|
|
|
def factorization_of_integer_divisible_by_all_integers_up_to(n)
|
|
|
|
{}.tap do |factorization|
|
|
|
|
(2..n).map do |i|
|
2014-12-05 00:50:52 +00:00
|
|
|
Prime.prime_division(i).map do |prime, exponent|
|
|
|
|
factorization[prime] = exponent if (!factorization.include?(prime) || (exponent > factorization[prime]))
|
2014-04-25 23:59:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-20 19:38:31 +00:00
|
|
|
def factors_to_int(factorization)
|
2014-12-05 00:50:52 +00:00
|
|
|
factorization.map { |prime, exponent| prime ** exponent }.inject(:*)
|
2014-11-20 19:38:31 +00:00
|
|
|
end
|
2014-04-25 23:59:14 +00:00
|
|
|
|
2014-11-20 19:38:31 +00:00
|
|
|
def solution
|
|
|
|
factors_to_int(factorization_of_integer_divisible_by_all_integers_up_to(20))
|
|
|
|
end
|