Created
October 24, 2021 02:56
-
-
Save moniquelive/5c4387bffe5a2413fea9f2d36f8c96d4 to your computer and use it in GitHub Desktop.
Manually scramble a vector in python... because why not
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
from random import randint | |
v = [1, 2, 3, 4, 5, 6, 7, 8, 9] | |
def swap(v, f, t): | |
print(f, t) | |
v[f] ^= v[t] | |
v[t] ^= v[f] | |
v[f] ^= v[t] | |
def scramble(v): | |
lv = len(v) | |
for i in range(lv-1): | |
swap(v, i, randint(i+1, lv-1)) | |
print(v) | |
scramble(v) | |
print(v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment