Racket 前n个奇数的平方和的递归过程?

Racket 前n个奇数的平方和的递归过程?,racket,Racket,我试图实现球拍上前n个奇数的平方和的递归过程 (从1开始) e、 (平方和递归0)为0 (和1)是1(1^2) (和2)是10(3^2+1^2) (平方和递归3)是35(5^2+3^2+1^2)这是一个使用线性迭代过程的递归过程 (define (sum-alt-squares-recursive x (y 1) (z 0)) (if (zero? x) z ; if x is zero, return

我试图实现球拍上前n个奇数的平方和的递归过程 (从1开始) e、 (平方和递归0)为0 (和1)是1(1^2) (和2)是10(3^2+1^2)
(平方和递归3)是35(5^2+3^2+1^2)

这是一个使用线性迭代过程的递归过程

(define (sum-alt-squares-recursive x (y 1) (z 0))
  (if (zero? x)
      z                                        ; if x is zero, return accumulator z
      (sum-alt-squares-recursive (- x 1)       ; x goes down by 1 each iteration
                                 (+ y 2)       ; y starts at 1 and goes up by 2 each iteration
                                 (+ z (* y y)) ; z, goes up by y^2 each time
      )))

(sum-alt-squares-recursive 1) ; => 1
(sum-alt-squares-recursive 2) ; => 10
(sum-alt-squares-recursive 3) ; => 35

你试过什么?StackOverflow可以解决特定的问题,例如:“我试图用Y来表示X,但却发生了Z。我错在哪里了?”我们需要您提供更多帮助。
(定义(和alt平方n)(*1/3N(sub1(*4N)))
(谢谢!)