◷ Reading Time: 4 minutes
FlexRule.Extensions.Combinatorics
Calculates different arrangements of a set. for more information about the math behind check this paper.
Let’s say we have the following list:
permutations
Permutations are arrangements of objects (with or without repetition), the order does matter
permutations (list, repeat)
- Sample: A = [a,b,c]
- permutations(A,true)
- Result:
1 | 2 | 3 |
---|---|---|
a | b | c |
a | c | b |
b | a | c |
b | c | a |
c | a | b |
c | b | a |
combinations
Combinations are selections of objects, with or without repetition, the order does not matter.
combinations (list, number, repeat)
- Sample: A = [a,b,c]
- combinations(A, 2, true)
- Result:
1 | 2 |
---|---|
a | a |
a | b |
a | c |
b | b |
b | c |
c | c |
- combination(A, 2, false)
- Result:
1 | 2 |
---|---|
a | b |
a | c |
b | c |
variations
Variations are arrangements of selections of objects, where the order of the selected objects matters.
variations (list, number, repeat)
- Sample: A=[a,b,c]
- variations(A, 2,true)
- Result:
1 | 2 |
---|---|
a | a |
a | b |
a | c |
b | a |
b | b |
b | c |
c | a |
c | b |
c | c |
- variations(A, 2, false)
- Result:
1 | 2 |
---|---|
a | b |
a | c |
b | a |
c | a |
b | c |
c | b |