Horrible solution for day 6
This commit is contained in:
33
2020/day_6/custom_customs.py
Normal file
33
2020/day_6/custom_customs.py
Normal file
@@ -0,0 +1,33 @@
|
||||
with open('input') as f:
|
||||
data = [line.strip() for line in f.read().split('\n\n')]
|
||||
|
||||
def solve_a(data):
|
||||
count = 0
|
||||
for group in data:
|
||||
answers = set()
|
||||
for c in group:
|
||||
if c != '\n':
|
||||
answers.add(c)
|
||||
count += len(answers)
|
||||
return count
|
||||
|
||||
def solve_b(data):
|
||||
count = 0
|
||||
for group in data:
|
||||
count_map = {}
|
||||
for c in group:
|
||||
if c == '\n': continue
|
||||
if c in count_map:
|
||||
count_map[c] += 1
|
||||
else:
|
||||
count_map[c] = 1
|
||||
for k in count_map:
|
||||
if count_map[k] == len(group.split()): count += 1
|
||||
print(count_map, count, len(group.split()))
|
||||
|
||||
return count
|
||||
|
||||
|
||||
print(solve_a(data))
|
||||
print(solve_b(data))
|
||||
|
||||
2241
2020/day_6/input
Normal file
2241
2020/day_6/input
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user