(wat-aro)

無職から有職者にランクアップしました

SICP 問題 3.82

(define (random-in-range x1 x2)
  (+ x1 (random-integer (- x2 x1))))


(define (estimate-integral p x1 x2 y1 y2)
  (stream-map (lambda (n) (* n (- x2 x1) (- y2 y1)))
              (monte-carlo
               (stream-map p
                           (stream-map (lambda (x) (random-in-range x1 x2)) integers)
                           (stream-map (lambda (x) (random-in-range y1 y2)) integers))
               0.0 0.0)))