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.
53 lines
898 B
53 lines
898 B
5 years ago
|
package main
|
||
|
|
||
|
import (
|
||
5 years ago
|
"fmt"
|
||
|
|
||
5 years ago
|
student "student"
|
||
|
|
||
|
"lib"
|
||
5 years ago
|
)
|
||
|
|
||
5 years ago
|
func reduceInt(a []int, f func(int, int) int) {
|
||
5 years ago
|
acc := a[0]
|
||
|
for i := 1; i < len(a); i++ {
|
||
|
acc = f(acc, a[i])
|
||
|
}
|
||
|
fmt.Println(acc)
|
||
|
}
|
||
|
|
||
5 years ago
|
func main() {
|
||
5 years ago
|
f := []func(int, int) int{
|
||
|
func(accumulator, currentValue int) int {
|
||
|
return accumulator + currentValue
|
||
|
},
|
||
|
func(accumulator, currentValue int) int {
|
||
|
return accumulator - currentValue
|
||
|
},
|
||
|
func(accumulator, currentValue int) int {
|
||
|
return currentValue * accumulator
|
||
|
},
|
||
|
}
|
||
5 years ago
|
argInt := []int{}
|
||
|
|
||
|
type node struct {
|
||
5 years ago
|
a []int
|
||
5 years ago
|
functions []func(int, int) int
|
||
|
}
|
||
|
|
||
|
table := []node{}
|
||
|
for i := 0; i < 4; i++ {
|
||
5 years ago
|
argInt = lib.MultRandIntBetween(0, 50)
|
||
5 years ago
|
table = append(table, node{
|
||
|
a: argInt,
|
||
5 years ago
|
functions: f,
|
||
5 years ago
|
})
|
||
5 years ago
|
}
|
||
|
|
||
|
for _, v := range table {
|
||
|
for _, f := range v.functions {
|
||
5 years ago
|
lib.Challenge("ReduceInt", student.ReduceInt, reduceInt, v.a, f)
|
||
5 years ago
|
}
|
||
|
}
|
||
|
}
|