diff options
-rw-r--r-- | scratch/deepmind/part_two/shuffle.py | 20 | ||||
-rw-r--r-- | scratch/deepmind/part_two/todo.org | 4 |
2 files changed, 22 insertions, 2 deletions
diff --git a/scratch/deepmind/part_two/shuffle.py b/scratch/deepmind/part_two/shuffle.py new file mode 100644 index 000000000000..fdc5a8bd80ab --- /dev/null +++ b/scratch/deepmind/part_two/shuffle.py @@ -0,0 +1,20 @@ +import random + + +def get_random(floor, ceiling): + return random.randrange(floor, ceiling + 1) + + +def shuffle(xs): + n = len(xs) + for i in range(n - 1): + j = get_random(i + 1, n - 1) + xs[i], xs[j] = xs[j], xs[i] + + +sample_list = [1, 2, 3, 4, 5] +print('Sample list:', sample_list) + +print('Shuffling sample list...') +shuffle(sample_list) +print(sample_list) diff --git a/scratch/deepmind/part_two/todo.org b/scratch/deepmind/part_two/todo.org index 078613611618..228dd08ef3f6 100644 --- a/scratch/deepmind/part_two/todo.org +++ b/scratch/deepmind/part_two/todo.org @@ -13,8 +13,8 @@ ** DONE Apple Stocks ** DONE Highest Product of 3 ** DONE Product of All Other Numbers -** TODO Cafe Order Checker -** TODO In-Place Shuffle +** DONE Cafe Order Checker +** DONE In-Place Shuffle * Sorting, searching, and logarithms ** TODO Find Rotation Point ** TODO Find Repeat, Space Edition |