Project:
 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 ``` ```; calculating pi (define rand (let* ((a 3141592653) (c 2718281829) (m (expt 2 35)) (x 5772156649) (next (lambda () (let ((x-prime (modulo (+ (* a x) c) m))) (set! x x-prime) x-prime))) (k 103) (v (list->vector (reverse (let loop ((i k) (vs (list x))) (if (= i 1) vs (loop (- i 1) (cons (next) vs))))))) (y (next)) (init (lambda (s) (set! x s) (vector-set! v 0 x) (do ((i 1 (+ i 1))) ((= i k)) (vector-set! v i (next)))))) (lambda seed (cond ((null? seed) (let* ((j (quotient (* k y) m)) (q (vector-ref v j))) (set! y q) (vector-set! v j (next)) (/ y m))) ((eq? (car seed) 'get) (list a c m x y k v)) ((eq? (car seed) 'set) (let ((state (cadr seed))) (set! a (list-ref state 0)) (set! c (list-ref state 1)) (set! m (list-ref state 2)) (set! x (list-ref state 3)) (set! y (list-ref state 4)) (set! k (list-ref state 5)) (set! v (list-ref state 6)))) (else (init (modulo (numerator (inexact->exact (car seed))) m)) (rand)))))) (define (pi n) (define (square n) (* n n)) (define (sand?) (< (+ (square (rand)) (square (rand))) 1)) (do ((i 0 (+ i 1)) (p 0 (+ p (if (sand?) 1 0)))) ((= i n) (exact->inexact (* 4 p (/ n)))))) (display (pi 100000)) (newline) (define (bound-pi n) (let loop ((a (* 3 (sqrt 3))) (b (* 3 (sqrt 3) (/ 2))) (n n)) (if (= n 1) (values b a) (let ((next-a (/ 2 (+ (/ a) (/ b))))) (loop next-a (sqrt (* next-a b)) (- n 1)))))) (call-with-values (lambda () (bound-pi 6)) (lambda (b a) (display b) (newline) (display a) (newline))) ```
 ```1 2 3 ``` ```3.14188 3.14103195089051 3.1427145996453683 ```