summaryrefslogtreecommitdiff
path: root/2015/day2.exs
blob: 47a00ec736fd06b1dc2aa473f7ebd051bf5efa3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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}")