defmodule AOC.Day6 do use AOC.Day, day: 6 def parse_input(lines), do: lines |> hd() |> String.to_charlist() def part1(input) do find_marker(input, 0, 4) end def part2(input) do find_marker(input, 0, 14) end def find_marker(signal, index, length) do distinct = signal |> Enum.take(length) |> MapSet.new() |> Enum.count() if distinct == length do index + length else signal |> tl() |> find_marker(index + 1, length) end end end