diff options
Diffstat (limited to '13.py')
-rw-r--r-- | 13.py | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -6,19 +6,17 @@ with open_day(13) as f: pairs = [tuple(literal_eval(v) for v in p.split('\n')) for p in f.read().rstrip().split('\n\n')] def compare(l, r): - if isinstance(l, list): - if isinstance(r, list): + match (l, r): + case ([*l], [*r]): for a, b in zip(l, r): - cmp = compare(a, b) - if cmp != 0: - return cmp + cmp = compare(a, b) + if cmp != 0: return cmp return compare(len(l), len(r)) - else: + case ([*l], int(r)): return compare(l, [r]) - else: - if isinstance(r, list): + case (int(l), [*r]): return compare([l], r) - else: + case (int(l), int(r)): return min(max(l - r, -1), 1) p1 = 0 |