Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

AoC 2022 - fork

2022/day06.livemd

AoC 2022 - fork

Mix.install([
  {:kino, "~> 0.7.0"},
  {:kino_vega_lite, "~> 0.1.6"}
])

Input

input_field = Kino.Input.textarea("Puzzle input")
input = Kino.Input.read(input_field)

Part 1

idx =
  input
  |> String.graphemes()
  |> Enum.chunk_every(4, 1)
  |> Enum.map(fn l ->
    size = Enum.count(l)
    uniq = Enum.uniq(l) |> Enum.count()
    size == uniq
  end)
  |> Enum.find_index(& &1)

idx + 4

Part 2

idx =
  input
  |> String.graphemes()
  |> Enum.chunk_every(14, 1)
  |> Enum.map(fn l ->
    size = Enum.count(l)
    uniq = Enum.uniq(l) |> Enum.count()
    size == uniq
  end)
  |> Enum.find_index(& &1)

idx + 14