Day 6
This commit is contained in:
parent
bc5112c849
commit
ea798b7313
|
@ -1,4 +1,17 @@
|
|||
input = []
|
||||
with open('day6_input.txt', 'r') as f:
|
||||
group = ''
|
||||
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]))
|
|
@ -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]))
|
Loading…
Reference in New Issue