Code for the Advent of Code event
aoc
advent-of-code
1local input = io.open("input.txt", "r")
2
3local total = 0
4
5local function min(a, b, c)
6 local nums = {}
7
8 if a < b then
9 nums[#nums + 1] = a
10 nums[#nums + 1] = b < c and b or c
11 else
12 nums[#nums + 1] = b
13 nums[#nums + 1] = a < c and a or c
14 end
15
16 return unpack(nums)
17end
18
19for line in input:lines("l") do
20 local l, w, h = line:match("(%d+)x(%d+)x(%d+)")
21 l = tonumber(l)
22 w = tonumber(w)
23 h = tonumber(h)
24
25 total = total + l * w * h
26
27 local a, b = min(l, w, h)
28 total = total + 2 * (a + b)
29end
30
31print("Total feet of ribbon required: " .. total)
32
33input:close()