From 428e5dcb37bb2d5d4fc6cb903457025010105602 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Fri, 6 Sep 2024 16:49:14 +0200 Subject: Day 2 --- 2015/day2.exs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 2015/day2.exs 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}") -- cgit v1.2.3