Day 03 (minified)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
h,d,a=0,0,0
|
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))
|
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)
|
print(h*d)
|
||||||
|
|||||||
2
day03/part1.min.py
Normal file
2
day03/part1.min.py
Normal 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
2
day03/part2.min.py
Normal 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))
|
||||||
Reference in New Issue
Block a user