summaryrefslogtreecommitdiff
path: root/2015/day1.exs
blob: ddb26d5b96c8e7a8944c84c92a789070dd03a4fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
contents = File.read!("inputs/day1.txt")
codepoints = String.codepoints(contents)

floors =
  Enum.map(codepoints, fn
    "(" -> 1
    ")" -> -1
  end)
  |> Enum.scan(0, &(&1 + &2))

endFloor = List.last(floors)
firstBasement = Enum.find_index(floors, fn x -> x < 0 end) + 1

IO.puts("Final floor: #{endFloor}")
IO.puts("First basement on instruction: #{firstBasement}")