Day 6: Add Lua solution
This commit is contained in:
parent
a47b1aff5b
commit
bae5181227
2 changed files with 34 additions and 0 deletions
1
06/input.txt
Normal file
1
06/input.txt
Normal file
|
@ -0,0 +1 @@
|
|||
1,1,3,5,1,1,1,4,1,5,1,1,1,1,1,1,1,3,1,1,1,1,2,5,1,1,1,1,1,2,1,4,1,4,1,1,1,1,1,3,1,1,5,1,1,1,4,1,1,1,4,1,1,3,5,1,1,1,1,4,1,5,4,1,1,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,5,1,1,1,3,4,1,1,1,1,3,1,1,1,1,1,4,1,1,3,1,1,3,1,1,1,1,1,3,1,5,2,3,1,2,3,1,1,2,1,2,4,5,1,5,1,4,1,1,1,1,2,1,5,1,1,1,1,1,5,1,1,3,1,1,1,1,1,1,4,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,2,1,1,1,1,2,2,1,2,1,1,1,5,5,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1,4,2,1,4,1,1,1,1,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,5,1,1,1,1,1,1,1,1,3,1,1,3,3,1,1,1,3,5,1,1,4,1,1,1,1,1,4,1,1,3,1,1,1,1,1,1,1,1,2,1,5,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1
|
33
06/solution.lua
Executable file
33
06/solution.lua
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env lua
|
||||
|
||||
fish = {}
|
||||
for i = 0, 8 do fish[i] = 0 end
|
||||
|
||||
function count_fish()
|
||||
count = 0
|
||||
for fi = 0, 8 do
|
||||
count = count + fish[fi]
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
for line in io.lines("input.txt") do
|
||||
for n in string.gmatch(line, "([^,]+)") do
|
||||
fish[tonumber(n)] = fish[tonumber(n)] + 1
|
||||
end
|
||||
|
||||
for iter = 1, 256 do
|
||||
f = fish[0]
|
||||
for fi = 0, 7 do
|
||||
fish[fi] = fish[fi+1]
|
||||
end
|
||||
fish[8] = f
|
||||
fish[6] = fish[6] + f
|
||||
|
||||
if iter == 80 then
|
||||
print("Solution 1:", count_fish())
|
||||
end
|
||||
end
|
||||
|
||||
print("Solution 2:", count_fish())
|
||||
end
|
Loading…
Reference in a new issue