Skip to content

Latest commit

 

History

History
36 lines (27 loc) · 608 Bytes

day_6.livemd

File metadata and controls

36 lines (27 loc) · 608 Bytes

Day 6

Mix.install([:kino])

Input

input = Kino.Input.textarea("Please enter your data here")

Part 1 & Part 2

number_of_distinct_letters = 14

input
|> Kino.Input.read()
|> String.to_charlist()
|> Enum.reduce_while({1, []}, fn
  char, {count, marker} ->
    marker = [char | marker]

    cond do
      length(Enum.uniq(marker)) == number_of_distinct_letters ->
        {:halt, count}

      length(marker) < number_of_distinct_letters ->
        {:cont, {count + 1, marker}}

      true ->
        {:cont, {count + 1, Enum.drop(marker, -1)}}
    end
end)