Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2022
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. def shuffle(L, sp):
  2. l1 = L[:sp]
  3. l2 = L[sp:]
  4. sh = []
  5. #for i in range(len(l1)):
  6. # sh = [l2[-1-i], l1[-1-i]] + sh
  7. sh = l1 + l1
  8. sh[::2] = L[-len(l1):]
  9. sh[1::2] = l1
  10. return l2[:len(l2)-len(l1)] + sh
  11.  
  12. def do_mapping(v1, v_map):
  13. v2 = v1[:]
  14. for i in range(len(v1)):
  15. v2[i] = v1[v_map[i]]
  16. return v2
  17.  
  18. def fast_search(nCards, iCut, n):
  19. original = list(range(nCards))
  20. L = list(range(nCards))
  21. precomputed = []
  22. c1 = 1
  23. for i in range(n):
  24. precomputed.append(L)
  25. L = shuffle(L, iCut)
  26. if L == original:
  27. return c1
  28. c1+=1
  29. #print(precomputed)
  30. #print("asdf", L==precomputed[9972], L, precomputed[9972])
  31. #big_shuffles = []
  32. count = 0
  33. deck = L[:]
  34. monitor = 1
  35. while deck not in precomputed:
  36. deck = do_mapping(deck, L)
  37. #big_shuffles.append(deck)
  38. count+=1
  39. #print(count*n)
  40. if count*n>monitor:
  41. print(monitor, count*n)
  42. monitor*=2
  43. j = 0
  44. while j<n:
  45. if precomputed[j]==deck:
  46. break
  47. j+=1
  48. #print(deck, count*n-j, count-1, n, j)
  49. return (count+1)*n-j
  50.  
  51. print(fast_search(1002,101,400000))
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement