You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
13 lines
280 B
Scheme
13 lines
280 B
Scheme
2 years ago
|
;;; doubly recursive power (expt) function
|
||
|
|
||
|
;;; try using trace-lambda to see the nesting.
|
||
|
|
||
|
(define power
|
||
|
(lambda (x n)
|
||
|
(cond
|
||
|
[(= n 0) 1]
|
||
|
[(= n 1) x]
|
||
|
[else
|
||
|
(let ([q (quotient n 2)])
|
||
|
(* (power x q) (power x (- n q))))])))
|