mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.1 KiB
78 lines
1.1 KiB
5 years ago
|
package main
|
||
5 years ago
|
|
||
5 years ago
|
import (
|
||
|
"fmt"
|
||
|
|
||
5 years ago
|
student "student"
|
||
|
|
||
|
"lib"
|
||
5 years ago
|
)
|
||
5 years ago
|
|
||
|
func show(n int, table [9]int, tmax [9]int) {
|
||
|
i := 0
|
||
|
for i < n {
|
||
|
fmt.Print(table[i])
|
||
|
i++
|
||
|
}
|
||
|
if table[0] != tmax[0] {
|
||
|
fmt.Print(", ")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func printComb1() {
|
||
|
table := [9]int{0}
|
||
|
tmax := [9]int{9}
|
||
|
for table[0] <= tmax[0] {
|
||
|
show(1, table, tmax)
|
||
|
table[0]++
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
func printCombN(n int) {
|
||
5 years ago
|
table := [9]int{0, 1, 2, 3, 4, 5, 6, 7, 8}
|
||
|
tmax := [9]int{}
|
||
|
|
||
|
if n == 1 {
|
||
|
printComb1()
|
||
|
} else {
|
||
|
i := n - 1
|
||
|
j := 9
|
||
|
for i >= 0 {
|
||
|
tmax[i] = j
|
||
|
i--
|
||
|
j--
|
||
|
}
|
||
|
i = n - 1
|
||
|
for table[0] < tmax[0] {
|
||
|
if table[i] != tmax[i] {
|
||
|
show(n, table, tmax)
|
||
|
table[i]++
|
||
|
}
|
||
|
if table[i] == tmax[i] {
|
||
|
if table[i-1] != tmax[i-1] {
|
||
|
show(n, table, tmax)
|
||
|
table[i-1]++
|
||
|
j = i
|
||
|
for j < n {
|
||
|
table[j] = table[j-1] + 1
|
||
|
j++
|
||
|
}
|
||
|
i = n - 1
|
||
|
}
|
||
|
}
|
||
|
for table[i] == tmax[i] && table[i-1] == tmax[i-1] && i > 1 {
|
||
|
i--
|
||
|
}
|
||
|
}
|
||
|
show(n, table, tmax)
|
||
|
}
|
||
|
fmt.Println()
|
||
|
}
|
||
5 years ago
|
|
||
|
func main() {
|
||
|
table := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||
|
for _, arg := range table {
|
||
|
lib.Challenge("PrintCombN", student.PrintCombN, printCombN, arg)
|
||
|
}
|
||
|
}
|