diff options
Diffstat (limited to '2015/day1.exs')
-rw-r--r-- | 2015/day1.exs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/2015/day1.exs b/2015/day1.exs new file mode 100644 index 0000000..ddb26d5 --- /dev/null +++ b/2015/day1.exs @@ -0,0 +1,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}") |