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.
58 lines
875 B
58 lines
875 B
5 years ago
|
package main
|
||
5 years ago
|
|
||
|
import (
|
||
5 years ago
|
"fmt"
|
||
|
|
||
5 years ago
|
student "student"
|
||
|
|
||
|
"lib"
|
||
5 years ago
|
)
|
||
|
|
||
5 years ago
|
func forEach(f func(int), a []int) {
|
||
|
for _, el := range a {
|
||
|
f(el)
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
func add0(i int) {
|
||
|
fmt.Println(i)
|
||
|
}
|
||
|
func add1(i int) {
|
||
|
fmt.Println(i + 1)
|
||
|
}
|
||
|
func add2(i int) {
|
||
|
fmt.Println(i + 2)
|
||
|
}
|
||
|
func add3(i int) {
|
||
|
fmt.Println(i + 3)
|
||
|
}
|
||
|
|
||
5 years ago
|
func main() {
|
||
5 years ago
|
functions := []func(int){add0, add1, add2, add3}
|
||
5 years ago
|
|
||
|
type node struct {
|
||
5 years ago
|
f func(int)
|
||
|
a []int
|
||
5 years ago
|
}
|
||
|
|
||
|
table := []node{}
|
||
|
|
||
5 years ago
|
// 15 random slice of random ints with a random function from selection
|
||
5 years ago
|
for i := 0; i < 15; i++ {
|
||
5 years ago
|
function := functions[lib.RandIntBetween(0, len(functions)-1)]
|
||
5 years ago
|
table = append(table, node{
|
||
|
f: function,
|
||
5 years ago
|
a: lib.MultRandIntBetween(-1000000, 1000000),
|
||
5 years ago
|
})
|
||
5 years ago
|
}
|
||
|
|
||
|
table = append(table, node{
|
||
5 years ago
|
f: add0,
|
||
|
a: []int{1, 2, 3, 4, 5, 6},
|
||
5 years ago
|
})
|
||
|
|
||
|
for _, arg := range table {
|
||
5 years ago
|
lib.Challenge("ForEach", student.ForEach, forEach, arg.f, arg.a)
|
||
5 years ago
|
}
|
||
|
}
|