Skip to content

Commit

Permalink
factorial
Browse files Browse the repository at this point in the history
Signed-off-by: deemak <deema_k@mail.ru>
  • Loading branch information
deemakuzovkin committed Jun 12, 2021
1 parent e41ac14 commit 9d810a4
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 27 deletions.
32 changes: 23 additions & 9 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/combinatorics/factorial.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package combinatorics

import "math/big"

/*Factorial *big.Int*/
func Factorial(n int64) *big.Int {
var nn big.Int
return nn.MulRange(1, n)
}

/*Factorial int64*/
func FactorialInt(n int64) int64 {
return Factorial(n).Int64()
}

/*Factorial string*/
func FactorialString(n int64) string {
return Factorial(n).String()
}
21 changes: 3 additions & 18 deletions pkg/combinatorics/math-c-from-n-to-k.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ package combinatorics

import "math/big"

/*
c from n to k
n int64
k int64
return *big.Int
*/
/*Cnk big.Int*/
func Cnk(n, k int64) big.Int {
if k >= 0 && n >= k {
var nn, kkl, kkr, down, total big.Int
Expand All @@ -22,23 +17,13 @@ func Cnk(n, k int64) big.Int {
return *big.NewInt(0)
}

/*
c from n to k
n int64
k int64
return uint64
*/
/*Cnk uint64*/
func CnkUint(n, k int64) uint64 {
cBig := Cnk(n, k)
return cBig.Uint64()
}

/*
c from n to k
n int64
k int64
return string
*/
/*Cnk string*/
func CnkStr(n, k int64) string {
cBig := Cnk(n, k)
return cBig.String()
Expand Down
3 changes: 3 additions & 0 deletions pkg/combinatorics/permutations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package combinatorics

import "math/big"

/*Permutations big.Int*/
func Permutations(n int64) big.Int {
return *Factorial(n)
}

/*Permutations int64*/
func PermutationsInt(n int64) int64 {
return Factorial(n).Int64()
}

/*Permutations string*/
func PermutationStr(n int64) string {
return Factorial(n).String()
}
3 changes: 3 additions & 0 deletions pkg/combinatorics/placements.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package combinatorics

import "math/big"

/*Permutations big.Int*/
func Placement(n, k int64) *big.Int {
cnk := Cnk(n, k)
permutations := Permutations(k)
var down big.Int
return down.Mul(&cnk, &permutations)
}

/*Permutations int64*/
func PlacementInt(n, k int64) int64 {
return Placement(n, k).Int64()
}

/*Permutations string*/
func PlacementStr(n, k int64) string {
return Placement(n, k).String()
}
1 change: 1 addition & 0 deletions pkg/sort/merge-sort.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sort

/*Permutations []int*/
func Merge(input []int) []int {
length := len(input)
if length < 2 {
Expand Down
1 change: 1 addition & 0 deletions pkg/sort/sort-by-insertion.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sort

/*Insertion []int*/
func Insertion(input []int) []int {
for j := 1; j < len(input); j++ {
key := input[j]
Expand Down

0 comments on commit 9d810a4

Please sign in to comment.