Day 6: Tuning Trouble
Mix.install([:kino])
Section
input = Kino.Input.textarea("input")
defmodule Comms do
def marker_at(stream, marker_length) do
stream
|> Stream.chunk_every(marker_length, 1)
|> Enum.reduce_while(marker_length, fn marker, acc ->
if marker |> Enum.uniq() |> length() == marker_length do
{:halt, acc}
else
{:cont, acc + 1}
end
end)
end
end
stream =
input
|> Kino.Input.read()
|> String.to_charlist()
Part1
Comms.marker_at(stream, 4)
Part 2
Comms.marker_at(stream, 14)