1
0
Fork 0

2018 day 2

This commit is contained in:
Lucidiot 2018-12-02 12:17:10 +01:00
parent 731606231e
commit 28d3677a68
No known key found for this signature in database
GPG Key ID: AE3F7205692FA205
2 changed files with 29 additions and 0 deletions

12
2018/2/part1.py Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env python3
import fileinput
from collections import Counter
def main():
n2, n3 = map(sum, zip(*map(lambda c: (2 in c.values(), 3 in c.values()), map(Counter, map(str.strip, fileinput.input())))))
return n2 * n3
if __name__ == '__main__':
print(main())

17
2018/2/part2.py Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env python3
import fileinput
from collections import Counter
def main():
ids = set(map(str.strip, fileinput.input()))
for i in range(len(ids)):
sliced = [boxid[:i] + boxid[i+1:] for boxid in ids]
if len(set(sliced)) == len(ids):
continue
return next(k for k, v in Counter(sliced).items() if v > 1)
if __name__ == '__main__':
print(main())