Unable to load image

The luckiest of days, Day 13!!

Let's fricking gooo!

17
Jump in the discussion.

No email address required.

Fun little "write a comparator then sort with it" challenge.


import ast
foo = []
with open('day13_input.txt', 'r') as inp:
    foo = inp.read().split('\n')
bar = [[[2]],[[6]]]
for f in foo:
    if len(f) > 0:
        bar.append(ast.literal_eval(f))
        
def eval(a, b):
    ta = str(type(a))
    tb = str(type(b))
    if ta == tb == "<class 'int'>":
        if a < b:
            return True
        elif a > b:
            return False
        return None
    if ta != tb:
        if ta == "<class 'int'>":
            a = [a]
        else:
            b = [b]
    for n in range(min(len(a), len(b))):
        e = eval(a[n], b[n])
        if e != None:
            return e
    if len(b) < len(a):
        return False
    elif len(b) > len(a):
        return True
    return None

for f in range(len(bar)):
    for g in range(len(bar)):
        if f != g:
            if eval(bar[f], bar[g]):
                temp = bar[f]
                bar[f] = bar[g]
                bar[g] = temp
print((1+bar.index([[2]]))*(1+bar.index([[6]])))
Jump in the discussion.

No email address required.

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