Slow string operations in pypy
I have been revisiting some advent of code examples. For my solution for day 16 from 2016 it seems as pypy 3.9 runs "forever" (left it running for ~10 minutes) while regular python 3.9.4 installation gives the correct result in 13 seconds. Here is the simple code (does not use any libraries, just plain python code):
def dragon(a):
b = a[::-1].replace('0','r').replace('1','0').replace('r','1')
return a+'0'+b
def diffstr(a):
b = ""
for i in range(0,len(a),2):
b += ['0','1'][a[i] == a[i+1]]
return b
def iterdiff(a):
b = a
while(len(b) % 2 == 0):
b = diffstr(b)
return b
size = 35651584
initstate = '10010000000110000'
while(len(initstate) < size):
initstate = dragon(initstate)
initstate = initstate[:size]
print(iterdiff(initstate))
Any ideas why it gets stuck? I am running on Windows if that matters.