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

Advent of Code 2022 - Day 06

livebooks/day_06.livemd

Advent of Code 2022 - Day 06

Mix.install([
  {:kino, "~> 0.8.0"}
])

Setup

example_value = """
mjqjpqmgbljsphdztnvjfqwrcgsmlb
"""

input = Kino.Input.textarea("Puzzle Input", default: example_value)

Section

input
|> Kino.Input.read()
|> String.trim()
|> String.graphemes()
|> Enum.chunk_every(4, 1, :discard)
|> Enum.take_while(fn group ->
  Enum.count(Enum.uniq(group)) != 4
end)
|> Enum.count()
|> then(&(&1 + 4))

Part 2

input
|> Kino.Input.read()
|> String.trim()
|> String.graphemes()
|> Enum.chunk_every(14, 1, :discard)
|> Enum.take_while(fn group ->
  Enum.count(Enum.uniq(group)) != 14
end)
|> Enum.count()
|> then(&(&1 + 14))