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.

I was very :marseybrainlet:, tried %(length-1), thought it didn't work, and then did it in an incredibly roundabout way.

f = open('AOC2022Day20.txt')
lst = [811589153*int(i) for i in f.read().strip().split('\n')]
newlst = copy.copy(lst)
indexes = [i for i in range(len(lst))]
for _ in range(10):
    for i in range(len(lst)):
        startindex = indexes.index(i)
        endindex = (lst[i]+startindex)
        while endindex >= len(lst) or endindex < 0:
            endindex = (endindex % len(lst))+endindex//len(lst)
        #endindex = endindex % (len(lst)-1)
        indval = indexes.pop(startindex)
        indexes.insert(endindex,indval)
        val = newlst.pop(startindex)
        newlst.insert(endindex,val)
zeroind = newlst.index(0)
val1 = newlst[(zeroind+1000)%len(newlst)]
val2 = newlst[(zeroind+2000)%len(newlst)]
val3 = newlst[(zeroind+3000)%len(newlst)]
print(val1+val2+val3)
Jump in the discussion.

No email address required.

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