move out c/cpp/py

This commit is contained in:
Li Jie
2025-04-03 15:52:18 +08:00
parent 0a8a4eb6a6
commit ed366568b4
777 changed files with 4608 additions and 139122 deletions

36
cl/_testgo/tprecur/in.go Normal file
View File

@@ -0,0 +1,36 @@
package main
func main() {
recursive()
}
func recursive() {
type T int
if got, want := recur1[T](5), T(110); got != want {
panic("error")
}
}
type Integer interface {
~int | ~int32 | ~int64
}
func recur1[T Integer](n T) T {
if n == 0 || n == 1 {
return T(1)
} else {
return n * recur2(n-1)
}
}
func recur2[T Integer](n T) T {
list := make([]T, n)
for i, _ := range list {
list[i] = T(i + 1)
}
var sum T
for _, elt := range list {
sum += elt
}
return sum + recur1(n-1)
}