Unable to load image

The luckiest of days, Day 13!!

Let's fricking gooo!

17
Jump in the discussion.

No email address required.

I wasted way too much time trying to parse the input without help. Otherwise not too bad.

import ast
import numpy as np
f = open('AOC2022Day13.txt')
pairs = f.read().strip().split('\n\n')
def comPair(l1,l2):
    if len(l1) == 0:
        if len(l2) == 0:
            return 0
        return 1
    if len(l2) == 0:
        return -1
    e1 = l1[0]
    e2 = l2[0]
    if not isinstance(e1,list) and not isinstance(e2,list):
        result = np.sign(e2-e1)
        if result != 0:
            return result
        return comPair(l1[1:],l2[1:])
    if not isinstance(e1,list):
        result = comPair([e1],e2)
        if result != 0:
            return result
        return comPair(l1[1:],l2[1:])
    if not isinstance(e2,list):
        result = comPair(e1,[e2])
        if result != 0:
            return result
        return comPair(l1[1:],l2[1:])
    else:
        result = comPair(e1,e2)
        if result != 0:
            return result
        return comPair(l1[1:],l2[1:])
    
allk = []
total = 0
for i in range(len(pairs)):
    pair = pairs[i].split('\n')
    l1 = ast.literal_eval(pair[0])
    l2 = ast.literal_eval(pair[1])
    allk.append(l1)
    allk.append(l2)
    v = comPair(l1,l2)
    if v == 1:
        total += i+1
allk.append([[2]])
allk.append([[6]])
from functools import cmp_to_key
s = sorted(allk, key = cmp_to_key(comPair), reverse=True)
print((s.index([[2]])+1)*(s.index([[6]])+1))
Jump in the discussion.

No email address required.

comPair :lol::wow:

Jump in the discussion.

No email address required.

Oh, a wild :marseyfrontiersman: mottizen appeared. Hi west :marseywave3:

Jump in the discussion.

No email address required.

Tech support told me about AoC and invited me to join :celebrate:

Jump in the discussion.

No email address required.

downvoted for making me look at camel case. please put a trigger warning next time.

edit: oops i meant to reply to @LetsUnpackThis's comment :marseyretard2:

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.