summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2024-09-06 16:14:36 +0200
committerJustin Wernick <justin@worthe-it.co.za>2024-09-06 16:14:36 +0200
commit43fa240f096fd4e257bce15f8095f3ce691782b9 (patch)
tree6bdfe508d537ac45dd0052969aef2cbeb17a8a92
parent939fb8cd409117da1c1ef9d13bfb143520912c76 (diff)
Day 1 of AOC2015 in Elixir
-rw-r--r--2015/day1.exs15
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}")