2023-12-04 19:49:23 -05:00
|
|
|
--@name aoc2023d2p2
|
2023-12-04 03:13:36 -05:00
|
|
|
--@author logan2611
|
|
|
|
--@client
|
|
|
|
|
|
|
|
games = string.explode("\n", string.trim(file.read("aoc2023d2input.txt")))
|
|
|
|
|
|
|
|
sum = 0
|
|
|
|
|
|
|
|
for i, v in ipairs(games) do
|
|
|
|
local curGame = string.gsub(string.trim(v),"^Game .*: ","")
|
|
|
|
|
2023-12-04 19:49:23 -05:00
|
|
|
local min = {
|
|
|
|
red = 0,
|
|
|
|
green = 0,
|
|
|
|
blue = 0
|
|
|
|
}
|
|
|
|
|
2023-12-04 03:13:36 -05:00
|
|
|
local pulls = string.explode("; ", string.trim(curGame))
|
|
|
|
for _, pull in ipairs(pulls) do
|
|
|
|
local blocks = string.explode(", ", string.trim(pull))
|
|
|
|
for _, block in ipairs(blocks) do
|
|
|
|
local block_ = string.explode(" ", block)
|
|
|
|
local num = tonumber(block_[1])
|
|
|
|
local color = block_[2]
|
|
|
|
|
2023-12-04 19:49:23 -05:00
|
|
|
if min[color] < num then
|
|
|
|
min[color] = num
|
2023-12-04 03:13:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-12-04 19:49:23 -05:00
|
|
|
local pow = min["red"] * min["green"] * min["blue"]
|
|
|
|
sum = sum + pow
|
2023-12-04 03:13:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
print(sum)
|