Created
December 16, 2022 10:16
-
-
Save iglesias/99b6fe0bf499e422101e003315c03da3 to your computer and use it in GitHub Desktop.
Advent of Code 2022 - Day 13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import functools | |
| import sys | |
| def compare(lleft, lright): | |
| print(">> ", end='') | |
| print(lleft) | |
| print(">> ", end='') | |
| print(lright) | |
| lleftc = lleft.copy() | |
| lrightc = lright.copy() | |
| for i in range(max(len(lleftc), len(lrightc))): | |
| print(' %d %d %d' % (i, len(lleftc), len(lrightc))) | |
| if i == len(lleftc): | |
| return 1 | |
| elif i == len(lrightc): | |
| return -1 | |
| if isinstance(lleftc[i], int) and isinstance(lrightc[i], int): | |
| if lleftc[i] < lrightc[i]: | |
| return 1 | |
| elif lleftc[i] > lrightc[i]: | |
| return -1 | |
| else: | |
| if isinstance(lleftc[i], int): | |
| lleftc[i] = list([lleftc[i]]) | |
| if isinstance(lrightc[i], int): | |
| lrightc[i] = list([lrightc[i]]) | |
| r = compare(lleftc[i], lrightc[i]) | |
| if r==1 or r==-1: | |
| return r | |
| return 0 | |
| ''' | |
| l = [[], [[]]] | |
| print('>> %d' % compare(l[0], l[1])) | |
| l = sorted(l, key=functools.cmp_to_key(compare), reverse=True) | |
| print(l) | |
| ''' | |
| l = [] | |
| while True: | |
| line = sys.stdin.readline() | |
| if len(line)==0: | |
| break | |
| lleft = eval(line) | |
| line = sys.stdin.readline() | |
| lright = eval(line) | |
| l.append(lleft) | |
| l.append(lright) | |
| sys.stdin.readline() | |
| l.append([[2]]) | |
| l.append([[6]]) | |
| l = sorted(l, key=functools.cmp_to_key(compare), reverse=True) | |
| ans = 1 | |
| for i in range(len(l)): | |
| if l[i] == [[2]]: ans *= i+1 | |
| if l[i] == [[6]]: ans *= i+1 | |
| print(l[i]) | |
| print(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment