adventofcode-2021/day06/part1.lua
Felix Van der Jeugt 602bc416d8
day 7
2021-12-07 08:29:45 +01:00

27 lines
521 B
Lua
Executable File

#!/usr/bin/env luajit
require("utils")
require("deque")
local fishes = deque()
for timer = 0, 9 do
fishes:append(0)
end
for _, timer in pairs(split(io.open(arg[3]):read("*a"), ",")) do
fishes:set(tonumber(timer), fishes:get(tonumber(timer)) + 1)
end
for day = 1, 80 do
local breeding = fishes:popleft() or 0
fishes:append(0)
fishes:set(8, (fishes:get(8) or 0) + breeding)
fishes:set(6, (fishes:get(6) or 0) + breeding)
end
local sum = 0
while fishes.size > 0 do
sum = sum + (fishes:pop() or 0)
end
print(sum)