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