15 lines
522 B
Scheme
15 lines
522 B
Scheme
(module montecarlo mzscheme
|
|
;; a seed specially chosen because it isn't terribly erratic when converging on pi
|
|
(random-seed 846259386)
|
|
|
|
(define (run)
|
|
(let loop ([hits 1]
|
|
[total 1])
|
|
(let* ([x (- (random 401) 200)]
|
|
[y (- (random 401) 200)]
|
|
[length (sqrt (+ (* x x) (* y y)))]
|
|
[pi (* 4. (/ hits total))])
|
|
(cond [(length . < . 200)
|
|
(loop (add1 hits) (add1 total))]
|
|
[else (loop hits (add1 total))]))))
|
|
(run)) |