Skip to content

Instantly share code, notes, and snippets.

@gbvanrenswoude
Created December 8, 2022 12:39
Show Gist options
  • Save gbvanrenswoude/354984cccf8ad7062cdc4e32ac987290 to your computer and use it in GitHub Desktop.
Save gbvanrenswoude/354984cccf8ad7062cdc4e32ac987290 to your computer and use it in GitHub Desktop.
pi.lisp
(require :cl)
(defun calc-pi (n)
(let ((in-circle 0))
(loop for i from 1 to n do
(let ((x (random 1.0))
(y (random 1.0)))
(when (< (+ (* x x) (* y y)) 1)
(incf in-circle))))
(* 4 (/ in-circle n))))
(defun main ()
(format t "~A~%" (calc-pi 100000)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment