Advent of Code 2015 Day 20 Part 1
Mix.install([
{:kino_aoc, "~> 0.1"}
])
Get Inputs
{:ok, puzzle_input} =
KinoAOC.download_puzzle("2015", "20", System.fetch_env!("LB_SESSION"))
My answer
get_divisers = fn limit ->
divisors = Enum.into(1..limit, %{}, fn index -> {index, []} end)
Enum.reduce(1..limit, divisors, fn i, acc ->
Enum.reduce(i..limit//i, acc, fn j, acc_inner ->
Map.put(acc_inner, j, [i | Map.get(acc_inner, j)])
end)
end)
end
get_divisers.(9)
target_number = String.to_integer(puzzle_input)
divisors_map = get_divisers.(1000000)
1..1000000
|> Enum.find(fn house_number ->
divisors = Map.get(divisors_map, house_number)
divisors
|> Enum.filter(fn num -> div(house_number, num) <= 50 end)
|> Enum.sum()
|> Kernel.>=(target_number / 11)
end)