Last active
December 10, 2015 01:18
-
-
Save kbob/4356791 to your computer and use it in GitHub Desktop.
https://plus.google.com/u/0/114070220225686847236/posts/d7xrq9ph7WJ There are no repeated digits, and no adjacent digits with a difference of one, in the number 13524. How many such arrangements of 5 digits are there? What's the shortest program you can write to find out?
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
#!/usr/bin/python | |
# https://plus.google.com/u/0/114070220225686847236/posts/d7xrq9ph7WJ | |
# There are no repeated digits, and no adjacent digits with a | |
# difference of one, in the number 13524. How many such arrangements | |
# of 5 digits are there? What's the shortest program you can write to | |
# find out? | |
import itertools | |
print sum(s[0] and all(abs(s[i] - s[i+1]) - 1 | |
for i in range(4)) | |
for s in itertools.permutations(range(10), 5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shorten this by changing map(int, '0123456789') to range(10).