
def solve(players, last_marble):
    marbles = [0]
    index = 0
    scores = [0]*(1+players)
    for marble in range(1, last_marble+1):
        if marble % 23 == 0:
            p = marble%players
            scores[p] += marble
            index -= 7
            if index < 0:
                index = len(marbles)+index
            scores[p] += marbles.pop(index)
        else:
            index += 2
            if index > len(marbles):
                index = 1
            marbles.insert(index, marble)
    return max(scores)

print(solve(9, 25))

print(solve(10, 1618), 8317)
print(solve(13, 7999), 146373)
print(solve(17, 1104), 2764)
print(solve(21, 6111), 54718)
print(solve(30, 5807), 37305)

print(solve(435, 71184))
# Too slow for part 2 due to using non-linked-list

@@ -1,8 +1,38 @@
+from collections import deque%0A
 %0Adef sol
@@ -33,16 +33,22 @@
 ef solve
+_deque
 (players
@@ -81,25 +81,18 @@
 s = 
-%5B0%5D%0A    index = 0
+deque(%5B0%5D)
 %0A   
@@ -268,87 +268,25 @@
     
-index -= 7%0A            if index %3C 0:%0A                index = len(marbles)+index
+marbles.rotate(7)
 %0A   
@@ -318,22 +318,21 @@
 bles.pop
-(index
+left(
 )%0A      
@@ -355,81 +355,26 @@
     
-index += 2%0A            if index %3E len(marbles):%0A                index = 1
+marbles.rotate(-2)
 %0A   
@@ -394,22 +394,19 @@
 les.
-insert(index, 
+appendleft(
 marb
@@ -444,16 +444,22 @@
 nt(solve
+_deque
 (9, 25))
@@ -459,17 +459,16 @@
 9, 25))%0A
-%0A
 print(so
@@ -470,16 +470,22 @@
 nt(solve
+_deque
 (10, 161
@@ -505,16 +505,22 @@
 nt(solve
+_deque
 (13, 799
@@ -542,16 +542,22 @@
 nt(solve
+_deque
 (17, 110
@@ -577,16 +577,22 @@
 nt(solve
+_deque
 (21, 611
@@ -613,16 +613,22 @@
 nt(solve
+_deque
 (30, 580
@@ -650,16 +650,22 @@
 nt(solve
+_deque
 (435, 71
@@ -674,55 +674,39 @@
 4))%0A
-# Too slow for part 2 due to using non-linked-list
+print(solve_deque(435, 71184*100))
 %0A

Rewrite solution with deque