Sorted
Mathematical
Let there be n different objects. To find the number of combinations of n objects by k, we will choose combinations of m objects in all possible ways, while paying attention to the different composition of the combinations, but not the order (it is not important here, unlike the placements).
The factorial operation is encountered in many areas of mathematics, notably in combinatorics, algebra, and mathematical analysis. Its most basic use counts the possible distinct sequences – the permutations – of n distinct objects: there are n!.
Permutations differ from combinations, which are selections of some members of a set regardless of order. For example, written as tuples, there are six permutations of the set {1,2,3}, namely: (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), and (3,2,1). These are all the possible orderings of this three-element set. Anagrams of words whose letters are different are also permutations: the letters are already ordered in the original word, and the anagram is a reordering of the letters. The study of permutations of finite sets is an important topic in the fields of combinatorics and group theory.
If you are already familiar with combinations, then you will easily notice that in order to find placements, you need to take all possible combinations, and then change the order in each one in all possible ways (that is, in fact, make more permutations). Therefore, the number of placements is also expressed in terms of the number of permutations and combinations
go get github.com/digital-technology-agency/math/pkg/combinatorics
go test -run ''
C from n to k
import "github.com/digital-technology-agency/math/pkg/combinatorics"
func Example() {
n := 100
k := 3
value := combinatorics.CnkUint(n, k)
fmt.Printf("Result: %d", value)
/*
Result: 161700
*/
}
If you don't need an ordered list of, Process's would be the best choice for large n.
N | n | k | Process |
---|---|---|---|
1 | 100 | 3 | 0.00s |
2 | 100000 | 3 | 0.09s |
3 | 1000000 | 3 | 3.52s |
Factorial (n!)
import "github.com/digital-technology-agency/math/pkg/combinatorics"
func Example() {
n := 4
value := combinatorics.FactorialInt(n)
fmt.Printf("Result: %d", value)
/*
Result: 24
*/
}
If you don't need an ordered list of factorial, Process's would be the best choice for large n.
N | n! | Process |
---|---|---|
1 | 10 | 0.00s |
2 | 100000 | 0.16s |
3 | 1000000 | 1.76s |
Permutations (n)
import "github.com/digital-technology-agency/math/pkg/combinatorics"
func Example() {
n := 4
value := combinatorics.PermutationsInt(n)
fmt.Printf("Result: %d", value)
/*
Result: 24
*/
}
Placements (A from n to k)
import "github.com/digital-technology-agency/math/pkg/combinatorics"
func Example() {
n := 10
k := 10
value := combinatorics.PlacementInt(n,k)
fmt.Printf("Result: %d", value)
/*
Result: 3628800
*/
}
- Go to main page and click Releases
- Choose a version for your operating system and click the link
- Download and unzip the math file
- Open terminal in unzip folder
- Run unzip binary file math and show list types
./math
- Comand argument list
./math -h
- Set arguments
./math -n=10000 -k=10
Pull requests and Github issues are welcome. Please read our contributing guide for more information.