fork download
  1. ;calculate Pi using Monte Carlo Method
  2. (defn pi [sample-size]
  3. (loop [c 0 in 0]
  4. (if (< c sample-size)
  5. (recur (inc c)
  6. (if (let [x (rand) y (rand)] (>= 1 (+ (* x x) (* y y))))
  7. (inc in)
  8. in))
  9. (* 4.0 (/ in sample-size)))))
  10.  
  11. (println(pi 3242242))
Success #stdin #stdout 2.61s 214656KB
stdin
Standard input is empty
stdout
3.142550124265863