day 6
This commit is contained in:
parent
0582895825
commit
992473a1ee
30
day06/part1.lua
Normal file
30
day06/part1.lua
Normal 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
0
day06/part2.lua
Normal file
Loading…
Reference in New Issue
Block a user