day 06 && 07
This commit is contained in:
46
day06/module.py
Normal file
46
day06/module.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from aoc.input import get_input
|
||||
import collections
|
||||
import re
|
||||
from aoc.partselector import part_one, part_two
|
||||
|
||||
def pw(line):
|
||||
return line.strip()
|
||||
|
||||
def p1():
|
||||
inp = get_input(pw)
|
||||
groups = []
|
||||
group = []
|
||||
for i in inp:
|
||||
if i == '':
|
||||
groups.append(group)
|
||||
group = []
|
||||
else:
|
||||
group.append(i)
|
||||
|
||||
count = 0
|
||||
for g in groups:
|
||||
answers = set()
|
||||
for p in g:
|
||||
for x in p:
|
||||
answers.add(x)
|
||||
count += len(answers)
|
||||
print(count)
|
||||
return groups
|
||||
|
||||
|
||||
def p2(r):
|
||||
count = 0
|
||||
for g in r:
|
||||
s = set(g[0])
|
||||
for p in g[1:]:
|
||||
s = s.intersection(p)
|
||||
count += len(s)
|
||||
print(count)
|
||||
return 0
|
||||
|
||||
if part_one():
|
||||
result1 = p1()
|
||||
|
||||
|
||||
if part_two():
|
||||
p2(result1)
|
||||
Reference in New Issue
Block a user