split code and remove prints

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

View File

@ -10,16 +10,12 @@ for _, timer in pairs(split(io.open(arg[3]):read("*a"), ",")) do
fishes[tonumber(timer)] = fishes[tonumber(timer)] + 1 fishes[tonumber(timer)] = fishes[tonumber(timer)] + 1
end end
for day = 1, 256 do for day = 1, 80 do
fishes[9] = (fishes[0] or 0) + (fishes[9] or 0) fishes[9] = (fishes[0] or 0) + (fishes[9] or 0)
fishes[7] = (fishes[0] or 0) + (fishes[7] or 0) fishes[7] = (fishes[0] or 0) + (fishes[7] or 0)
for timer = 0, 9 do for timer = 0, 9 do
fishes[timer] = fishes[timer + 1] fishes[timer] = fishes[timer + 1]
end end
for k = 0, 9 do
io.write((fishes[k] or "_")..",")
end
io.write("\n")
end end
local sum = 0 local sum = 0

View File

@ -0,0 +1,26 @@
#!/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
end
local sum = 0
for timer, fishday in pairs(fishes) do
sum = sum + fishday
end
print(sum)