SHARE
TWEET

Untitled

a guest Mar 2nd, 2018 170 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import itertools
  2. import random
  3.  
  4. def shuffle(cards):
  5.     num = cards[0]
  6.     return [cards[i] if i > num-1 else cards[num-1-i] for i in range(len(cards))]
  7.  
  8. def finish_shuffling(cards):
  9.     num_iterations = 0
  10.     while cards[0] != 1:
  11.         cards = shuffle(cards)
  12.         num_iterations += 1
  13.     return num_iterations
  14.  
  15.  
  16. def final_calc(deck_size):
  17.     results = {}
  18.     highest = 0
  19.     for cards in itertools.permutations(range(1,deck_size+1)):
  20.         num = finish_shuffling(cards)
  21.         if num in results:
  22.             results[num] += 1
  23.         else:
  24.             results[num] = 1
  25.         if num > highest:
  26.             highest = num
  27.             print cards
  28.             print num
  29.             print '\n'
  30.     return results
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top