Skip to content

Instantly share code, notes, and snippets.

@dominicgs
Created May 24, 2016 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominicgs/4601e6fd2378881d289d5af84fa66654 to your computer and use it in GitHub Desktop.
Save dominicgs/4601e6fd2378881d289d5af84fa66654 to your computer and use it in GitHub Desktop.
Perfect card shuffling example
#!/usr/bin/env python
decks = [range(1, 53)]
def shuffle(deck):
a = deck[:len(deck)/2]
b = deck[len(deck)/2:]
c = zip(a, b)
return c
print "Initial deck:"
print decks[-1]
for i in range(8):
pairs = shuffle(decks[-1])
decks.append(list(sum(pairs, ())))
print
print "Iteration: %d" % (i+1)
print decks[-1]
print
print "Final deck:"
print decks[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment