This commit is contained in:
Felix Van der Jeugt 2021-12-06 08:37:48 +01:00
parent 0582895825
commit 992473a1ee
No known key found for this signature in database
GPG Key ID: 58B209295023754D
2 changed files with 30 additions and 0 deletions

30
day06/part1.lua Normal file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env luajit
require("utils")
local fishes = {}
for timer = 0, 9 do
fishes[timer] = 0
end
for _, timer in pairs(split(io.open(arg[3]):read("*a"), ",")) do
fishes[tonumber(timer)] = fishes[tonumber(timer)] + 1
end
for day = 1, 256 do
fishes[9] = (fishes[0] or 0) + (fishes[9] or 0)
fishes[7] = (fishes[0] or 0) + (fishes[7] or 0)
for timer = 0, 9 do
fishes[timer] = fishes[timer + 1]
end
for k = 0, 9 do
io.write((fishes[k] or "_")..",")
end
io.write("\n")
end
local sum = 0
for timer, fishday in pairs(fishes) do
sum = sum + fishday
end
print(sum)

0
day06/part2.lua Normal file
View File