3 (define (monte-carlo trials experiment)
4 (define (iter trials-remaining trials-passed)
6 ((= trials-remaining 0) (/ trials-passed trials))
7 ((experiment) (iter (- trials-remaining 1) (+ trials-passed 1)))
8 (else (iter (- trials-remaining 1) trials-passed))))
14 (define (random-in-range low high)
15 (let ((range (- high low)))
16 (+ low (random range))))
19 (define (inside-circle? radius centre-x centre-y)
20 (<= (+ (square (- x centre-x))
21 (square (- y centre-y)))
23 (inside-circle? 1.0 0 0))
25 (define (estimate-integral P x1 x2 y1 y2 trials)
27 (let ((x (random-in-range x1 x2))
28 (y (random-in-range y1 y2)))
30 (define (rectangle-area x1 x2 y1 y2)
31 (* (- x2 x1) (- y2 y1)))
33 (* (monte-carlo trials in-region)
34 (rectangle-area x1 x2 y1 y2)))