Created
March 1, 2013 07:04
-
-
Save Y4suyuki/5062950 to your computer and use it in GitHub Desktop.
Udacity Design of Computer Analysis
This file contains 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
def swap(deck, i, j): | |
"Swap elements i and j of a collection." | |
print 'swap', i, j | |
deck[i], deck[j] = deck[j], deck[i] | |
def shuffle2(deck): | |
"A modification of my teacher's algo" | |
N = len(deck) | |
swapped = [False] * N | |
while not all(swapped): | |
i, j = randrange(N), randrange(N) | |
swapped[i] = True | |
swap(deck, i, j) | |
def shuffle3(deck): | |
"An easier modification of my t's algo" | |
N = len(deck) | |
for i in range(N) | |
swap(deck, i, randrange(N)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment