Day 01
Mix.install([
{:kino, "~> 0.19.0"}
])
Section
input = """
57
57
55
57
76
78
57
45
43
78
43
76
43
78
57
45
57
76
43
43
76
"""
content =
Kino.FS.file_path("input.txt")
|> File.read!()
defmodule Part1 do
def run(input) when is_binary(input) do
input
|> String.split()
|> Enum.map(&String.to_integer/1)
|> Enum.frequencies()
|> Enum.to_list()
|> Enum.sort_by(&elem(&1, 1), :desc)
|> Enum.take(3)
|> Enum.product_by(&elem(&1, 0))
end
end
186276 = Part1.run(input)
114404778 = Part1.run(content)
defmodule Part2 do
def run(input) when is_binary(input) do
input
|> String.split()
|> Enum.map(&String.to_integer/1)
|> Enum.frequencies()
|> Enum.to_list()
|> Enum.sort_by(&elem(&1, 1), :asc)
|> Enum.take(3)
|> Enum.product_by(&elem(&1, 0))
end
end
193050 = Part2.run(input)
301848182 = Part2.run(content)