From 43fa240f096fd4e257bce15f8095f3ce691782b9 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Fri, 6 Sep 2024 16:14:36 +0200 Subject: Day 1 of AOC2015 in Elixir --- 2015/day1.exs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 2015/day1.exs (limited to '2015/day1.exs') 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}") -- cgit v1.2.3