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

Advent of Code 2015 Day 3 Part 1

2015_day3_part1.livemd

Advent of Code 2015 Day 3 Part 1

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

Get Inputs

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

My answer

puzzle_input
|> String.codepoints()
|> Enum.reduce({{0, 0}, [{0, 0}]}, fn direction, {{x, y}, houses} ->
  new_point =
    case direction do
      ">" -> {x + 1, y}
      "<" -> {x - 1, y}
      "^" -> {x, y + 1}
      _ -> {x, y - 1}
    end

  {new_point, [new_point | houses]}
end)
|> elem(1)
|> Enum.uniq()
|> length()