From 85e623a9dbeff95c1c91e075cc546289672a06d2 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Tue, 13 Dec 2022 10:39:36 -0800 Subject: [PATCH] day 13 python cleanup convert our less function into a real cmp function --- day13/sol.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/day13/sol.py b/day13/sol.py index bd3bbbe..9ba7025 100644 --- a/day13/sol.py +++ b/day13/sol.py @@ -4,38 +4,31 @@ data = [] for chunk in open("input").read().split("\n\n"): data.append([json.loads(x) for x in chunk.splitlines(False)]) -def less(a, b): +def cmp(a, b): if type(a) == int and type(b) == int: - return a < b + return (a > b) - (a < b) if type(a) == list and type(b) == int: b = [b] elif type(a) == int and type(b) == list: a = [a] for x, y in zip(a,b): - if less(x,y): - return True - elif less(y,x): - return False - return len(a)=") - if less(a,b): + if cmp(a,b) < 0: t += i + 1 print(t) import functools -def cmp(a, b): - if less(a,b): - return -1 - if less(b,a): - return 1 - return 0 big = [e for x in data for e in x] big.append([[2]])