36 lines
No EOL
867 B
Lua
36 lines
No EOL
867 B
Lua
--@name aoc2023d2p2
|
|
--@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 .*: ","")
|
|
|
|
local min = {
|
|
red = 0,
|
|
green = 0,
|
|
blue = 0
|
|
}
|
|
|
|
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]
|
|
|
|
if min[color] < num then
|
|
min[color] = num
|
|
end
|
|
end
|
|
end
|
|
|
|
local pow = min["red"] * min["green"] * min["blue"]
|
|
sum = sum + pow
|
|
end
|
|
|
|
print(sum) |