Created
May 20, 2014 06:54
-
-
Save ucarion/aaab81841a3ce3ba4c3c to your computer and use it in GitHub Desktop.
Same thing, but in Python
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
import copy | |
import random | |
people = [0, 1, 2, 3, 4, 5, 6, 7] | |
tries = 1000000 | |
count = 0 | |
for _ in range(tries): | |
shuffled_people = copy.copy(people) | |
random.shuffle(shuffled_people) | |
any_same_place = any([p[0] == p[1] for p in enumerate(shuffled_people)]) | |
if not(any_same_place): | |
count += 1 | |
print(float(count) / tries) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment