This commit is contained in:
cupcakearmy 2020-12-06 11:41:25 +01:00
parent f87c4b6aaf
commit ad6001e572
3 changed files with 43 additions and 0 deletions

View File

@ -4,4 +4,6 @@ Here are my solutions for the advent of code 2020 🎄🎅
Note that the exact solutions are different for some people. Note that the exact solutions are different for some people.
The main ones are solved in python. 1-4 I also did in Go, but I quickly [did not like it](./learning/Go.md).
`/solutions/:day/*` `/solutions/:day/*`

13
solutions/6/README.md Normal file
View File

@ -0,0 +1,13 @@
# 6
Basically I own this one to the built in `set()` of python.
The first is an union, the second an intersection. Did not know they existed
<details>
<summary>Solutions</summary>
<ol>
<li>6809</li>
<li>3394</li>
</ol>
</details>

View File

@ -0,0 +1,28 @@
from os.path import join, dirname
from itertools import product
from typing import List, Set, Tuple
from functools import reduce
data = join(dirname(__file__), '../data.txt')
with open(data) as f:
groups = f.read().strip().split('\n\n')
at_least_one: List[int] = []
everyone: List[int] = []
for group in groups:
answers: Set[str] = set()
combined = None
for answer in group.split('\n'):
answer = answer.strip()
as_set = set(list(answer))
answers = answers.union(as_set)
combined = as_set if combined == None else combined.intersection(
as_set)
at_least_one.append(len(answers))
everyone.append(len(combined))
# print(single)
# print(reduce(lambda a, b: a.intersection(b), single))
print(f'At least one person: {sum(at_least_one)}')
print(f'Everyone: {sum(everyone)}')