Skip to content

Instantly share code, notes, and snippets.

@benhowes
Created May 24, 2015 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benhowes/f0efa87467fe45d62044 to your computer and use it in GitHub Desktop.
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}
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
@benhowes
Copy link
Author

Prints 92520 when run

@benhowes
Copy link
Author

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