Created
May 24, 2015 15:19
-
-
Save benhowes/f0efa87467fe45d62044 to your computer and use it in GitHub Desktop.
How Many 5-permutations that contain at least one number are there for the following set {a,b,c,d,e,f,g,1,2,3,4,5}
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
from itertools import permutations | |
s = ['a','b','c','d','e','f','g',1,2,3,4,5] | |
perms = permutations(s,5) | |
# The following line does this: | |
# For each 5-permutation, see if there is an instance of an integer in it (isinstance). | |
# If there is, add one to a temporary list which we then sum to give the total count. | |
count = sum([1 for p in perms if sum([isinstance(_, int) for _ in p])]) | |
print count |
P(12,5) - P(7,5) seems like the obvious answer, since that is all sets of 5, minus all possible combinations which only have letters.
P(12,5) - P(7,5) = 92520
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prints
92520
when run