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}")