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.
34 lines
535 B
34 lines
535 B
5 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"math/bits"
|
||
|
|
||
5 years ago
|
student "student"
|
||
|
|
||
4 years ago
|
"github.com/01-edu/public/go/tests/lib"
|
||
5 years ago
|
)
|
||
|
|
||
|
func recursiveFactorial(nb int) int {
|
||
|
limit := 20
|
||
|
if nb < 0 || nb > limit {
|
||
|
return 0
|
||
|
}
|
||
|
if nb == 0 {
|
||
|
return 1
|
||
|
}
|
||
5 years ago
|
return nb * recursiveFactorial(nb-1)
|
||
5 years ago
|
}
|
||
|
|
||
|
func main() {
|
||
|
if bits.UintSize != 64 {
|
||
|
panic("only works on 64 bits CPU")
|
||
|
}
|
||
|
table := append(
|
||
|
lib.MultRandInt(),
|
||
|
lib.IntRange(0, 20)...,
|
||
|
)
|
||
|
for _, arg := range table {
|
||
|
lib.Challenge("RecursiveFactorial", student.RecursiveFactorial, recursiveFactorial, arg)
|
||
|
}
|
||
|
}
|