Day 03 (minified)

This commit is contained in:
Sebastian Seedorf
2021-12-04 19:57:36 +01:00
parent 37cd737f3a
commit 53abaa4d01
3 changed files with 5 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
h,d,a=0,0,0
for c,s in(x.strip().split()for x in open("input.txt")):v=int(s);h,d,a=(h+v,d+a*v,a)if c[0]=='f'else(h,d,a+(-v if c=='up'else v))
print(h*d)

2
day03/part1.min.py Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env python3
from collections import Counter as o;g=int("".join((o(c).most_common(1)[0][0]for c in zip(*(x.strip()for x in open("input.txt"))))),2);print(g*(2**12-1^g))

2
day03/part2.min.py Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env python3
import collections as c;n=lambda w:(f:=lambda i,l:int(''.join(l),2) if i>11else f(i+1,[s for s in l if s[i]==(max if w else min)(map(lambda x:x[::-1],c.Counter(s[i] for s in l).items()))[1]]))(0,[x.strip()for x in open("input.txt")]);print(n(0)*n(1))