Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (declaim (optimize (speed 3) (safety 0) (debug 0) (compilation-speed 0)))
- (defconstant *size* 20000)
- (defconstant *rect* 999)
- (defconstant *full* (+ 1 *rect* *size*))
- (defconstant *rect-count* 2000)
- (defun make-prng ()
- (let ((s 123456789))
- (lambda ()
- (prog1 s
- (setf s (mod (+ (* s 22695477) 12345) 1073741824))))))
- (defun make-rect-generator ()
- (let ((prng (make-prng)))
- (lambda ()
- (vector (mod (funcall prng) *size*) (mod (funcall prng) *size*)
- (1+ (mod (funcall prng) *rect*)) (1+ (mod (funcall prng) *rect*))))))
- (defun area-fill (area rect)
- (dotimes (y (aref rect 3) rect)
- (dotimes (x (aref rect 2))
- (setf (aref area (+ x (aref rect 0)) (+ y (aref rect 1))) 1))))
- (defun area ()
- (let ((area (make-array (list *full* *full*) :element-type 'bit))
- (gen (make-rect-generator))
- (sum 0))
- (dotimes (i *rect-count*)
- (area-fill area (funcall gen)))
- (dotimes (y *full* sum)
- (dotimes (x *full*)
- (when (= (aref area x y) 1)
- (incf sum))))))
- (time (format t "Area: ~:d units~%" (area)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement