day 13, with help
This commit is contained in:
parent
33fd08d182
commit
abe366b3b3
|
@ -0,0 +1,33 @@
|
||||||
|
import sys
|
||||||
|
|
||||||
|
P = [ tuple(map(eval, p.split("\n"))) for p in sys.stdin.read().split("\n\n") ]
|
||||||
|
|
||||||
|
def C(l,r):
|
||||||
|
T = (type(l),type(r))
|
||||||
|
if T == (int,int):
|
||||||
|
if l<r: return -1
|
||||||
|
return l>r # 0 or 1
|
||||||
|
if T == (int,list):
|
||||||
|
return C([l],r)
|
||||||
|
if T == (list,int):
|
||||||
|
return C(l,[r])
|
||||||
|
# list,list
|
||||||
|
for q in zip(l,r):
|
||||||
|
c = C(*q)
|
||||||
|
if c: return c
|
||||||
|
return C(len(l),len(r))
|
||||||
|
|
||||||
|
# part 1
|
||||||
|
S = 0
|
||||||
|
for i,p in enumerate(P):
|
||||||
|
if C(*p) <= 0:
|
||||||
|
S += i+1
|
||||||
|
print(S)
|
||||||
|
|
||||||
|
# part 2
|
||||||
|
from functools import cmp_to_key
|
||||||
|
Q = [ q for (l,r) in P for q in [l,r] ]
|
||||||
|
Q.append([[2]])
|
||||||
|
Q.append([[6]])
|
||||||
|
Q.sort(key=cmp_to_key(C))
|
||||||
|
print((Q.index([[2]])+1)*(Q.index([[6]])+1))
|
Loading…
Reference in New Issue