|
|
|
@ -4,13 +4,24 @@ import (
|
|
|
|
|
"github.com/01-edu/z01" |
|
|
|
|
|
|
|
|
|
correct "./correct" |
|
|
|
|
student "./student" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
|
f := []func(int, int) int{Add, Sub, Mul} |
|
|
|
|
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 |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type node struct { |
|
|
|
|
arr []int |
|
|
|
|
a []int |
|
|
|
|
functions []func(int, int) int |
|
|
|
|
n int |
|
|
|
|
} |
|
|
|
@ -19,41 +30,28 @@ func main() {
|
|
|
|
|
|
|
|
|
|
for i := 0; i < 8; i++ { |
|
|
|
|
argInt = append(argInt, z01.MultRandIntBetween(0, 50)...) |
|
|
|
|
val := node{ |
|
|
|
|
arr: argInt, |
|
|
|
|
table = append(table, node{ |
|
|
|
|
a: argInt, |
|
|
|
|
functions: f, |
|
|
|
|
n: z01.RandIntBetween(0, 60), |
|
|
|
|
} |
|
|
|
|
table = append(table, val) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
table = append(table, node{ |
|
|
|
|
arr: []int{1, 2, 3}, |
|
|
|
|
a: []int{1, 2, 3}, |
|
|
|
|
functions: f, |
|
|
|
|
n: 93, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
table = append(table, node{ |
|
|
|
|
arr: []int{0}, |
|
|
|
|
a: []int{0}, |
|
|
|
|
functions: f, |
|
|
|
|
n: 93, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
for _, v := range table { |
|
|
|
|
for _, f := range v.functions { |
|
|
|
|
z01.Challenge("FoldInt", FoldInt, correct.FoldInt, f, v.arr, v.n) |
|
|
|
|
z01.Challenge("FoldInt", student.FoldInt, correct.FoldInt, f, v.a, v.n) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func Add(accumulator, currentValue int) int { |
|
|
|
|
return accumulator + currentValue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func Sub(accumulator, currentValue int) int { |
|
|
|
|
return accumulator - currentValue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func Mul(accumulator, currentValue int) int { |
|
|
|
|
return currentValue * accumulator |
|
|
|
|
} |
|
|
|
|