Something went wrong. Try again.
Code for the Advent of Code event
aoc advent-of-code
Something went wrong. Try again.
622 B · 33 lines
Lua
at main
12345678910111213141516171819202122232425262728293031323334local input = io.open("input.txt", "r")
local total = 0
local function min(a, b, c) local nums = {}
if a < b then nums[#nums + 1] = a nums[#nums + 1] = b < c and b or c else nums[#nums + 1] = b nums[#nums + 1] = a < c and a or c end
return unpack(nums)end
for line in input:lines("l") do local l, w, h = line:match("(%d+)x(%d+)x(%d+)") l = tonumber(l) w = tonumber(w) h = tonumber(h)
total = total + l * w * h
local a, b = min(l, w, h) total = total + 2 * (a + b)end
print("Total feet of ribbon required: " .. total)
input:close()