Skip to content

Instantly share code, notes, and snippets.

@Yoxem
Last active March 14, 2017 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yoxem/168556fb00d2d93abba8c4430eea6e87 to your computer and use it in GitHub Desktop.
Save Yoxem/168556fb00d2d93abba8c4430eea6e87 to your computer and use it in GitHub Desktop.
Find the approximation of pi
(define (pi-iter i max sum)
(if (= i max)
(* 4 sum)
(let ((k (/
(^ (- 1) i)
(+ (* 2 i) 1))))
(pi-iter (+ i 1) max (+
sum
k)))
))
(define (^ x y)
(cond ((= y 0) 1)
((= y 1) x)
(else (^-iter x 1 y x)))
)
(define (^-iter x i max result)
(if (= i max) result
(^-iter x (+ i 1) max (* x result))
))
(display "pi的近似值:")
(display (pi-iter 0 50000 0))
(newline)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment