diff options
Diffstat (limited to 'scratch/facebook/hard/fisher-yates.py')
-rw-r--r-- | scratch/facebook/hard/fisher-yates.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/scratch/facebook/hard/fisher-yates.py b/scratch/facebook/hard/fisher-yates.py new file mode 100644 index 000000000000..200d1613ddcb --- /dev/null +++ b/scratch/facebook/hard/fisher-yates.py @@ -0,0 +1,7 @@ +import random + +def shuffle(xs): + n = len(xs) + for i in range(n): + j = random.randint(i, n - 1) + xs[i], xs[j] = xs[j], xs[i] |