Skip to content

Instantly share code, notes, and snippets.

@Y4suyuki
Created March 1, 2013 07:04
Show Gist options
  • Save Y4suyuki/5062950 to your computer and use it in GitHub Desktop.
Save Y4suyuki/5062950 to your computer and use it in GitHub Desktop.
Udacity Design of Computer Analysis
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