-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13.py
37 lines (29 loc) · 930 Bytes
/
13.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from lib import *
input = read_input(2022, 13)
pairs = [tuple(map(eval, pair.splitlines())) for pair in input.split("\n\n")]
def compare(a, b):
if isinstance(a, int) and isinstance(b, int):
if a < b:
return True
elif a > b:
return False
else:
return None
if isinstance(a, int):
a = [a]
if isinstance(b, int):
b = [b]
for x, y in zip(a, b):
if (z := compare(x, y)) is not None:
return z
if len(a) < len(b):
return True
elif len(a) > len(b):
return False
else:
return None
print(sum((i + 1) * (compare(a, b) is True) for i, (a, b) in enumerate(pairs)))
packets = [[[2]], [[6]]] + [x for a, b in pairs for x in [a, b]]
out = sum(compare(packet, packets[0]) is True for packet in packets) + 1
out *= sum(compare(packet, packets[1]) is True for packet in packets) + 1
print(out)