Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Combinations/Go/combinations.go
Normal file
29
Task/Combinations/Go/combinations.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
comb(5, 3, func(c []int) {
|
||||
fmt.Println(c)
|
||||
})
|
||||
}
|
||||
|
||||
func comb(n, m int, emit func([]int)) {
|
||||
s := make([]int, m)
|
||||
last := m - 1
|
||||
var rc func(int, int)
|
||||
rc = func(i, next int) {
|
||||
for j := next; j < n; j++ {
|
||||
s[i] = j
|
||||
if i == last {
|
||||
emit(s)
|
||||
} else {
|
||||
rc(i+1, j+1)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
rc(0, 0)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue