Created
May 24, 2016 00:29
-
-
Save dominicgs/4601e6fd2378881d289d5af84fa66654 to your computer and use it in GitHub Desktop.
Perfect card shuffling example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "Iteration: %d" % (i+1) | |
print decks[-1] | |
print "Final deck:" | |
print decks[-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment