Day 2: I Was Told There Would Be No Math
Section
defmodule Foo do
def sum(s) do
[l, w, h] =
s
|> String.split("x")
|> Enum.map(&String.to_integer/1)
2 * l * w + 2 * w * h + 2 * h * l + Enum.min([l * w, w * h, h * l])
end
end
{:ok, data} = File.read("/Users/eli/Desktop/input.txt")
data
|> String.split("\n", trim: true)
|> Enum.map(&Foo.sum/1)
|> Enum.sum()
1606483
defmodule Foo2 do
def ribbon(s) do
[l, w, h] =
s
|> String.split("x")
|> Enum.map(&String.to_integer/1)
Enum.min([2 * l + 2 * w, 2 * w + 2 * h, 2 * h + 2 * l]) + l * w * h
end
end
{:ok, data} = File.read("/Users/eli/Desktop/input.txt")
data
|> String.split("\n", trim: true)
|> Enum.map(&Foo2.ribbon/1)
|> Enum.sum()
3842356