2020 day 6
This commit is contained in:
parent
47a5c60f13
commit
47b3d9fc19
|
@ -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)
|
Loading…
Reference in New Issue