My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update 2022/13

+22 -30
+22 -30
2022/day13.py
··· 1 1 import fileinput 2 2 3 3 4 - def right_order(a, b): 5 - for x, y in zip(a, b): 6 - if type(x) == int and type(y) == int: 7 - if int(x) < int(y): 8 - return True 9 - elif int(x) > int(y): 10 - return False 11 - else: 12 - continue 13 - elif type(x) == list and type(y) == list: 14 - # :( 15 - # if len(x) == 0: 16 - # return True 17 - # elif len(y) == 0: 18 - # return False 19 - ret = right_order(x, y) 20 - if ret is None: 21 - continue 22 - else: 23 - return ret 4 + def right_order(x, y): 5 + if type(x) == int and type(y) == int: 6 + if int(x) < int(y): 7 + return True 8 + elif int(x) > int(y): 9 + return False 24 10 else: 25 - if type(x) == int: 26 - ret = right_order([x], y) 27 - else: 28 - ret = right_order(x, [y]) 11 + return None 29 12 30 - if ret is None: 31 - continue 32 - return ret 13 + if type(x) == int: 14 + x = [x] 15 + if type(y) == int: 16 + y = [y] 33 17 34 - if len(a) < len(b): 18 + if len(x) == len(y) == 0: 19 + return None 20 + elif len(x) == 0: 35 21 return True 36 - elif len(a) > len(b): 22 + elif len(y) == 0: 37 23 return False 38 24 39 - return None 25 + x, *xs = x 26 + y, *ys = y 27 + 28 + ret = right_order(x, y) 29 + if ret is None: 30 + return right_order(xs, ys) 31 + return ret 40 32 41 33 42 34 # Solve part 1 while parsing input.