1
0
Fork 0

2020 day 6

This commit is contained in:
Lucidiot 2020-12-07 02:22:01 +01:00
parent 47a5c60f13
commit 47b3d9fc19
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
2 changed files with 30 additions and 1 deletions

29
2020/6/day6.lua Normal file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env lua
local groups, current = {}, {count=0}
for line in io.lines() do
if line == "" then
table.insert(groups, current)
current = {count=0}
else
for char in line:gmatch(".") do
current[char] = (current[char] or 0) + 1
end
current.count = current.count + 1
end
end
table.insert(groups, current)
local any_count, all_count = 0, 0
for _, group in ipairs(groups) do
for name, question_count in pairs(group) do
if name ~= "count" then
any_count = any_count + 1
if question_count == group.count then
all_count = all_count + 1
end
end
end
end
print(any_count)
print(all_count)

View File

@ -11,7 +11,7 @@ My solutions to the Advent of Code puzzles.
3 ██ ██ ██ ██ ██
4 ██ ██ ██ ██
5 ██ ██ ██ ██
6 ██ ██
6 ██ ██ ██
7 ██ ██
8 ██ ██
9 █ ██