Skip to content

Instantly share code, notes, and snippets.

@ucarion
Created May 20, 2014 06:54
Show Gist options
  • Save ucarion/aaab81841a3ce3ba4c3c to your computer and use it in GitHub Desktop.
Save ucarion/aaab81841a3ce3ba4c3c to your computer and use it in GitHub Desktop.
Same thing, but in Python
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