summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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}")