blob: 3d47677ba4fb30227748e96231f3e41ad7d6468e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
defmodule Solver.Day6 do
def marker([_h | tail] = line, distinct, counter) do
line
|> Enum.take(distinct)
|> MapSet.new()
|> MapSet.size()
|> Kernel.then(fn amount ->
case amount do
^distinct -> counter
_ -> marker(tail, distinct, counter + 1)
end
end)
end
def start(msg, distinct) do
String.graphemes(msg) |> marker(distinct, distinct) |> IO.puts()
end
end
case File.read("input") do
{:ok, body} ->
Solver.Day6.start(body, 4)
Solver.Day6.start(body, 14)
{:error, reason} ->
IO.puts(reason)
end
|