Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
108
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defparameter KEY "ljoxqyyw")
  2.  
  3. (defun countbits (ba)
  4.   (reduce #'+ ba))
  5.  
  6. (defun getrow (rown)
  7.   (hash (concatenate 'string KEY "-" (write-to-string rown))))
  8.  
  9. (defun total-bits ()
  10.   (let ((bitc 0))
  11.     (dotimes (i 128 bitc)
  12.       (incf bitc (countbits (getrow i))))))
  13.  
  14. (defun get-bitmap (nrows)
  15.   (make-array (list nrows 128)
  16.               :initial-contents
  17.               (loop
  18.                  for i upto (1- nrows)
  19.                  collect (getrow i))))
  20.  
  21. (defun colorize ()
  22.   (let ((bitmap (get-bitmap 128))
  23.         (colorized (make-array '(128 128) :initial-element 'nil))
  24.         (groups 0))
  25.     (labels ((color (x y)
  26.                (when (and (= 1 (aref bitmap x y))
  27.                           (not (aref colorized x y)))
  28.                  (setf (aref colorized x y) groups)
  29.                  (color (if (/= 0 x) (1- x) x) y)
  30.                  (color (if (/= 127 x) (1+ x) x) y)
  31.                  (color x (if (/= 0 y) (1- y) y))
  32.                  (color x (if (/= 127 y) (1+ y) y)))))
  33.       (dotimes (i 128 (values colorized groups))
  34.         (dotimes (j 128)
  35.           (when (and (= 1 (aref bitmap i j))
  36.                      (not (aref colorized i j)))
  37.             (incf groups)
  38.             (color i j)))))))
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement