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

Advent of Code 2015 - Day 1

advent-of-code/2015/day01.livemd

Advent of Code 2015 - Day 1

Mix.install([
  {:kino, "~> 0.14.2"},
  {:kino_vega_lite, "~> 0.1.13"},
  {:kino_explorer, "~> 0.1.23"}
])

Puzzle Input

puzzle_input = Kino.Input.textarea("Please paste the puzzle input:")

Part 1

part_1_test_input = Kino.Input.textarea("Please paste the test input for part 1:")
part_1_test_input
|> Kino.Input.read()
|> String.to_charlist()
|> Enum.reduce(0, fn
  ?(, acc ->
    acc + 1

  ?), acc ->
    acc - 1
end)
puzzle_input
|> Kino.Input.read()
|> String.to_charlist()
|> Enum.reduce_while({_floor = 0, _step = 0}, fn command, {floor, step} ->
  floor =
    case command do
      ?( ->
        floor + 1

      ?) ->
        floor - 1
    end

  step = step + 1

  if floor == -1 do
    {:halt, step}
  else
    {:cont, {floor, step}}
  end
end)

Part 2

part_2_test_input_kino = Kino.Input.textarea("Please paste the test input for part 2:")
part_2_test_input = Kino.Input.read(part_2_test_input_kino)
part_2_test_input
|> String.split("\n", trim: true)