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

Advent of Code 2022 - Day 6

2022/day06.livemd

Advent of Code 2022 - Day 6

Mix.install([:kino, {:kino_aoc, git: "https://github.com/ljgago/kino_aoc"}])

Input

test_input = "nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg"
{:ok, puzzle_input} = KinoAOC.download_puzzle("2022", "6", System.fetch_env!("LB_AOC_SESSION"))
input_field =
  Kino.Input.select("input", [
    {test_input, "test_input"},
    {puzzle_input, "puzzle_input"}
  ])

Parsing & Prep

solve = fn input_field, chars ->
  input_field
  |> Kino.Input.read()
  |> String.to_charlist()
  |> Enum.chunk_every(chars, 1, :discard)
  |> Enum.with_index(chars)
  |> Enum.find(fn {seq, _} ->
    seq
    |> Enum.uniq()
    |> Enum.count() == chars
  end)
  |> elem(1)
end

Part 1

solve.(input_field, 4)

Part 2

solve.(input_field, 14)