day 20 aoc: the cupid shuffle

https://youtube.com/watch?v=h24_zoqu4_Q

to the right to the right to the right

to the left to the left to the left

post your aoc solutions for day 20 or smth, all checks notes 5+ of you

42
Jump in the discussion.

No email address required.

Lazy, retarded and inefficient but hey, it works. I had to re-adapt it about 3 separate times because I was too stupid to read the problem correctly.

foo = []
with open('day20_input.txt', 'r') as inp:
    foo = [[int(i)*811589153,0] for i in inp.read().split('\n')]

index = 0
count = 1
while index < len(foo):
    if not foo[index][1]:
        val = foo[index][0]
        new_index = index+val
        foo = foo[:index] + foo[index+1:]
        foo = foo[:new_index%len(foo)] + [[val, count]] + foo[new_index%len(foo):]
        count += 1
    else:
        index += 1

for n in range(9):
    for f in range(1, len(foo)+1):
        for index in range(len(foo)):
            if foo[index][1] == f:
                val, count = foo[index][0], foo[index][1]
                new_index = index + val
                foo = foo[:index] + foo[index+1:]
                foo = foo[:new_index%len(foo)] + [[val, count]] + foo[new_index%len(foo):]
                break

z_index = None
for f in range(len(foo)):
    if foo[f][0] == 0:
        z_index = f
        break

print(foo[(z_index+1000)%len(foo)][0] + foo[(z_index+2000)%len(foo)][0] + foo[(z_index+3000)%len(foo)][0])

Jump in the discussion.

No email address required.

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