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}")