MIN_CARTES = 173 MAX_CARTES = 208 def melange(l): new = list() tmp = l.copy() move_to_new = False while len(tmp) > 0: if move_to_new: new.append(tmp[0]) tmp.pop(0) else: tmp = tmp[1:] + [tmp[0], ] move_to_new = not move_to_new return new[::-1] best = (0, 0) for i in range(MIN_CARTES, MAX_CARTES+1): start = [x for x in range(1, i+1)] l = start[::-1] ctr = 1 while True: new = melange(l) # print(new[::-1]) if new[::-1] == start: if ctr > best[1]: best = (i, ctr) break l = new.copy() ctr += 1 print(i, ctr) print(best)