Powered by AppSignal & Oban Pro

Advent of Code 2015 Day 1 Part 2

2015_day1_part2.livemd

Advent of Code 2015 Day 1 Part 2

Mix.install([
  {:kino_aoc, "~> 0.1"}
])

Get Inputs

{:ok, puzzle_input} =
  KinoAOC.download_puzzle("2015", "1", System.fetch_env!("LB_SESSION"))

My answer

puzzle_input
|> String.codepoints()
|> Enum.with_index(1)
|> Enum.reduce_while(0, fn {direction, index}, current ->
  current =
    case direction do
      "(" -> current + 1
      _ -> current - 1
    end

  if current < 0 do
    {:halt, index}
  else
    {:cont, current}
  end
end)