Created
February 17, 2018 13:26
-
-
Save risentveber/6fcfc55956b9320d4cd0e3038ed8c405 to your computer and use it in GitHub Desktop.
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 itertools | |
import math | |
import sys | |
count = 0 | |
n = int(sys.argv[1]) | |
for left in itertools.permutations(range(1, n + 1)): | |
for right in itertools.permutations(range(1, n + 1)): | |
rIsGood = all(i + 1 != r for i, r in enumerate(right)) | |
lIsGood = all(i + 1 != l for i, l in enumerate(left)) | |
if rIsGood or lIsGood: | |
print left, right | |
count += 1 | |
print count, math.factorial(n)**2 | |
print count / float(math.factorial(n)**2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment