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.
59 lines
968 B
59 lines
968 B
5 years ago
|
package main
|
||
|
|
||
|
import (
|
||
5 years ago
|
"fmt"
|
||
|
|
||
5 years ago
|
"./student"
|
||
5 years ago
|
)
|
||
|
|
||
5 years ago
|
func chunk(a []int, ch int) {
|
||
|
slice := []int{}
|
||
|
if ch <= 0 {
|
||
|
fmt.Println()
|
||
|
return
|
||
|
}
|
||
|
result := make([][]int, 0, len(a)/ch+1)
|
||
|
for len(a) >= ch {
|
||
|
slice, a = a[:ch], a[ch:]
|
||
|
result = append(result, slice)
|
||
|
}
|
||
|
if len(a) > 0 {
|
||
|
result = append(result, a[:len(a)])
|
||
|
}
|
||
|
fmt.Println(result)
|
||
|
}
|
||
|
|
||
5 years ago
|
func randomSize() []int {
|
||
|
randSlice := []int{}
|
||
5 years ago
|
for i := 0; i <= lib.RandIntBetween(0, 20); i++ {
|
||
|
randSlice = append(randSlice, lib.RandInt())
|
||
5 years ago
|
}
|
||
|
return randSlice
|
||
|
}
|
||
|
|
||
5 years ago
|
func main() {
|
||
5 years ago
|
type node struct {
|
||
|
slice []int
|
||
|
ch int
|
||
|
}
|
||
|
table := []node{}
|
||
|
|
||
|
for i := 0; i <= 7; i++ {
|
||
|
value := node{
|
||
|
slice: randomSize(),
|
||
5 years ago
|
ch: lib.RandIntBetween(0, 10),
|
||
5 years ago
|
}
|
||
|
table = append(table, value)
|
||
|
}
|
||
|
table = append(table, node{
|
||
|
slice: []int{},
|
||
|
ch: 0,
|
||
|
}, node{
|
||
|
slice: []int{1, 2, 3, 4, 5, 6, 7, 8},
|
||
|
ch: 0,
|
||
|
})
|
||
|
for _, args := range table {
|
||
5 years ago
|
lib.Challenge("Chunk", student.Chunk, chunk, args.slice, args.ch)
|
||
5 years ago
|
}
|
||
|
}
|