AoC 2023 Day 15
Mix.install([
{:kino_aoc, "~> 0.1.5"}
])
Input
{:ok, puzzle_input} =
KinoAOC.download_puzzle("2023", "15", System.fetch_env!("LB_AOC_COOKIE_SECRET"))
defmodule HASH do
def hash(string) when is_binary(string), do: hash(String.to_charlist(string))
def hash(string) do
for char <- string, reduce: 0 do
acc -> hash(char, acc)
end
end
def hash(num, current) do
next = (current + num) * 17
Integer.mod(next, 256)
end
end
Part 1
puzzle_input
|> String.split(",", trim: true)
|> Enum.map(&HASH.hash/1)
|> Enum.sum()
Part 2