Calculate permutations and combinations in go
With a correctly configured Go toolchain:
go get -u github.com/jaumecapdevila/gocap
First of all you need to create a new instance of the Operation struct using the NewOperation
constructor:
operation := NewOperation(3, 1, false)
This constructor receives three parameters:
- N: the number of different types
- R: the number of types to choose
- Repetition: Indicates if its possible or not to repeat a type
Now, you can use the CombinationCalculator
and the PermutationCalculator
to get the result of the operation:
calculator := NewCombinationCalculator()
result := calculator.Calculate(operation)
Jaume Capdevila – @otherjaume – contact@jaumecapdevila.net
Distributed under the MIT license.
https://github.com/jaumecapdevila/gocap
- Fork it (https://github.com/jaumecapdevila/gocap/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request