In Python, permutations and combinations can be displayed and calculated really intuitively, which is convenient.
The pattern of arrangement when the five elements a, b, c, d, and e meet is 5! (Factial factorial of 5). In other words
_5 P _5 = 5! = 5 * 4 * 3 * 2 * 1 = 120
To find this in Python
#coding:utf-8
import itertools
#Target to line up
s = ['a','b','c','d','e']
#list
p = list(itertools.permutations(s));
#Pattern display
#print p
#Number of patterns displayed
print len(p)
And. If you choose 3 out of 5 and arrange them
_5 P _3 = 5 * 4 * 3 = 60
Will be. If you want this in Python
p = list(itertools.permutations(s,3));
(Excerpt from the above).
Then permutation. Regardless of the order, if the elements are the same, they are counted as one. For example, (a, b, c) and (a, c, b) are considered to be one. Similar to the above, if you select 3 from a, b, c, d, e, the combination is
_5 C _3 = \frac{_5 P _3}{3!} = \frac{5 * 4 * 3}{3 * 2 * 1} = 10
Will be. To calculate this in Python
#coding:utf-8
import itertools
#Target to line up
s = ['a','b','c','d','e']
#list
c = list(itertools.combinations(s,3));
#Pattern display
#print c
#Number of patterns displayed
print len(c)
And.
Recommended Posts