mirror of
https://github.com/cupcakearmy/advent-of-code.git
synced 2024-12-21 23:56:30 +00:00
6
This commit is contained in:
parent
f87c4b6aaf
commit
ad6001e572
@ -4,4 +4,6 @@ Here are my solutions for the advent of code 2020 🎄🎅
|
||||
|
||||
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/*`
|
||||
|
13
solutions/6/README.md
Normal file
13
solutions/6/README.md
Normal 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>
|
28
solutions/6/python/main.py
Normal file
28
solutions/6/python/main.py
Normal 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)}')
|
Loading…
Reference in New Issue
Block a user