Advent of code day 16
Mix.install([
{:kino, "~> 0.5.0"}
])
Setup input
example = Kino.Input.textarea("Please paste your input example:")
input = Kino.Input.textarea("Please paste your real input:")
defmodule Solver do
import Bitwise
def step(n) do
n = Integer.mod(bxor(n * 64, n), 16_777_216)
n = Integer.mod(bxor(div(n, 32), n), 16_777_216)
Integer.mod(bxor(n * 2048, n), 16_777_216)
end
end
Part 01
example
|> Kino.Input.read()
|> String.split("\n", trim: true)
|> Enum.map(&String.to_integer/1)
|> Enum.map(fn x ->
Enum.reduce(0..1_999, x, fn _, x ->
Solver.step(x)
end)
end)
|> Enum.sum()
Part 02