3 ms·
You can improve that by around 13% if you soften the inequality (your > should be >=, I believe) table = {} s = 'ddddd' for i in range(100): if
by boothby 3y ago
You can improve that by around 13% if you soften the inequality (your > should be >=, I believe)
table = {}
s = 'ddddd'
for i in range(100):
if i%5 == 0:
print(s)
state = table.setdefault(s, {'f':0, 'd':0})
s = s[1:] + ('f' if state['f'] <= state['d'] > 0 else 'd')
state[s[-1]] += 1