mirror of
https://github.com/jneug/adventofcode.git
synced 2026-04-14 06:43:33 +02:00
Day 6
This commit is contained in:
@@ -1,4 +1,17 @@
|
|||||||
input = []
|
input = []
|
||||||
with open('day6_input.txt', 'r') as f:
|
with open('day6_input.txt', 'r') as f:
|
||||||
|
group = ''
|
||||||
for line in f.readlines():
|
for line in f.readlines():
|
||||||
input.append(line.strip())
|
if len(line.strip()) == 0:
|
||||||
|
input.append(group)
|
||||||
|
group = ''
|
||||||
|
else:
|
||||||
|
group += line.strip()
|
||||||
|
input.append(group)
|
||||||
|
|
||||||
|
def counter(group):
|
||||||
|
return len(set(group))
|
||||||
|
print(sum(map(counter, input)))
|
||||||
|
|
||||||
|
print(input[0])
|
||||||
|
print(set(input[0]))
|
||||||
20
2020/day6_2.py
Normal file
20
2020/day6_2.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
from functools import reduce
|
||||||
|
|
||||||
|
input = []
|
||||||
|
with open('day6_input.txt', 'r') as f:
|
||||||
|
group = []
|
||||||
|
for line in f.readlines():
|
||||||
|
if len(line.strip()) == 0:
|
||||||
|
input.append(group)
|
||||||
|
group = []
|
||||||
|
else:
|
||||||
|
group.append(line.strip())
|
||||||
|
input.append(group)
|
||||||
|
|
||||||
|
def intersec(s, g):
|
||||||
|
return s.intersection(set(g))
|
||||||
|
|
||||||
|
def counter(group):
|
||||||
|
return len(reduce(intersec, group, set(group[0])))
|
||||||
|
|
||||||
|
print(sum([counter(g) for g in input]))
|
||||||
Reference in New Issue
Block a user