summaryrefslogtreecommitdiff
path: root/2015/day2.exs
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2024-09-06 16:49:14 +0200
committerJustin Wernick <justin@worthe-it.co.za>2024-09-06 16:49:14 +0200
commit428e5dcb37bb2d5d4fc6cb903457025010105602 (patch)
tree63dde073cdd1985add494ae646b6aee908e52f33 /2015/day2.exs
parent43fa240f096fd4e257bce15f8095f3ce691782b9 (diff)
Day 2
Diffstat (limited to '2015/day2.exs')
-rw-r--r--2015/day2.exs27
1 files changed, 27 insertions, 0 deletions
diff --git a/2015/day2.exs b/2015/day2.exs
new file mode 100644
index 0000000..47a00ec
--- /dev/null
+++ b/2015/day2.exs
@@ -0,0 +1,27 @@
+stream = File.stream!("inputs/day2.txt", :line, [:read])
+
+materials =
+ for line <- stream, into: [] do
+ sides =
+ String.trim(line)
+ |> String.split("x", trim: true)
+ |> Enum.map(&String.to_integer(&1))
+ |> Enum.sort()
+
+ [w, l, h] = sides
+
+ %{wrapping: w * l * 3 + w * h * 2 + l * h * 2, ribbon: 2 * (w + l) + w * l * h}
+ end
+
+totalWrapping =
+ materials
+ |> Enum.map(& &1.wrapping)
+ |> Enum.sum()
+
+totalRibbon =
+ materials
+ |> Enum.map(& &1.ribbon)
+ |> Enum.sum()
+
+IO.puts("Wrapping used: #{totalWrapping}")
+IO.puts("Ribbon used: #{totalRibbon}")