Skip to content

Instantly share code, notes, and snippets.

@ignaciovazquez
Created December 2, 2015 19:45
Show Gist options
  • Save ignaciovazquez/f121e47e853111dad15b to your computer and use it in GitHub Desktop.
Save ignaciovazquez/f121e47e853111dad15b to your computer and use it in GitHub Desktop.
Advent of Code. Day 2.
result = Enum.reduce(tests, {0, 0}, fn (x, {paper, ribbon}) ->
[l, w, h] = String.split(x, "x") |> Enum.map(fn n ->
{number, _ } = Integer.parse(n)
number
end)
[a, b | _ ] = Enum.sort([l, w, h])
paper = paper + (2*l*w + 2*w*h + 2*h*l) + (a * b)
ribbon = ribbon + (l * w * h) + ((a * 2) + (b * 2))
{paper, ribbon}
end)
IO.inspect result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment