Advertisement
Guest User

rect.lisp

a guest
Sep 3rd, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.11 KB | None | 0 0
  1. (declaim (optimize (speed 3) (safety 0) (debug 0) (compilation-speed 0)))
  2.  
  3. (defconstant *size* 20000)
  4. (defconstant *rect* 999)
  5. (defconstant *full* (+ 1 *rect* *size*))
  6. (defconstant *rect-count* 2000)
  7.  
  8. (defun make-prng ()
  9.   (let ((s 123456789))
  10.     (lambda ()
  11.       (prog1 s
  12.         (setf s (mod (+ (* s 22695477) 12345) 1073741824))))))
  13.  
  14. (defun make-rect-generator ()
  15.   (let ((prng (make-prng)))
  16.     (lambda ()
  17.       (vector (mod (funcall prng) *size*)      (mod (funcall prng) *size*)
  18.           (1+ (mod (funcall prng) *rect*)) (1+ (mod (funcall prng) *rect*))))))
  19.  
  20. (defun area-fill (area rect)
  21.   (dotimes (y (aref rect 3) rect)
  22.     (dotimes (x (aref rect 2))
  23.       (setf (aref area (+ x (aref rect 0)) (+ y (aref rect 1))) 1))))
  24.  
  25. (defun area ()
  26.   (let ((area (make-array (list *full* *full*) :element-type 'bit))
  27.         (gen (make-rect-generator))
  28.         (sum 0))
  29.     (dotimes (i *rect-count*)
  30.       (area-fill area (funcall gen)))
  31.     (dotimes (y *full* sum)
  32.       (dotimes (x *full*)
  33.         (when (= (aref area x y) 1)
  34.           (incf sum))))))
  35.  
  36. (time (format t "Area: ~:d units~%" (area)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement