Unable to load image

The luckiest of days, Day 13!!

Let's fricking gooo!

17
Jump in the discussion.

No email address required.

    def compare(first, second):
        if first is None:
            return -1
        if second is None:
            return 1

        if isinstance(first, int) and isinstance(second, int):
            return first - second

        if isinstance(first, int):
            first = [first]
        if isinstance(second, int):
            second = [second]

        for a, b in itertools.zip_longest(first, second):
            c = compare(a, b)
            if c != 0:
                return c

        return 0

    if not second:
        res = 0
        for i, (first, second) in enumerate(grouper(data, 2)):
            first, second = ast.literal_eval(first), ast.literal_eval(second)
            r = compare(first, second)
            # print(i + 1, first, second, r)
            if r < 0:
                res += i + 1
        return res
    else:
        lst = [ast.literal_eval(it) for it in data]
        a, b = [[2]], [[6]]
        lst.append(a)
        lst.append(b)
        lst.sort(key=functools.cmp_to_key(compare))
        for i, it in enumerate(lst):
            if it == a:
                n1 = i + 1
            if it == b:
                n2 = i + 1
        return n1 * n2
Jump in the discussion.

No email address required.

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