Skip to content

Instantly share code, notes, and snippets.

@kbob
Last active December 10, 2015 01:18
Show Gist options
  • Save kbob/4356791 to your computer and use it in GitHub Desktop.
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?
#!/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))
@kbob
Copy link
Author

kbob commented Dec 22, 2012

Shorten this by changing map(int, '0123456789') to range(10).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment