Advertisement
Guest User

AoC day 10 B

a guest
Dec 10th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.22 KB | None | 0 0
  1. (load "~/quicklisp/setup.lisp")
  2. (ql:quickload "bit-smasher")
  3. (defparameter *lens*
  4.   (append (map 'list #'char-code "129,154,49,198,200,133,97,254,41,6,2,1,255,0,191,108")
  5.           '(17 31 73 47 23)))
  6.  
  7. (defparameter *list*
  8.   (loop for i upto 255 collect i))
  9. (rplacd (last *list*) *list*)
  10. (defparameter *lh* *list*)
  11.  
  12. (defparameter *skp* 0)
  13.  
  14. (defun reverseip (l len)
  15.   (if (= len 0)
  16.       l
  17.       (let ((lt (nthcdr len l)))
  18.         (rplacd (nthcdr (1- len) l) '())
  19.         (loop
  20.            for i from (1- (length l)) downto 0
  21.            for j upto (1- (length l))
  22.            do (if (or (< i j)
  23.                       (= i j))
  24.                   (return)
  25.                   (rotatef (nth j l) (nth i l))))
  26.         (nconc l lt)
  27.         l)))
  28.  
  29. (dotimes (i 64)
  30.   (dolist (len *lens*)
  31.     (reverseip *list* len)
  32.     (setf *list* (nthcdr (+ len *skp*) *list*))
  33.     (incf *skp*)))
  34.  
  35. (let ((denseh '()))
  36.   (dotimes (i 16)
  37.     (setf denseh
  38.           (nconc denseh
  39.                  (list
  40.                   (reduce #'bit-xor
  41.                           (mapcar #'bit-smasher:bits<-
  42.                                   (subseq *lh* (* 16 i) (+ (* 16 i) 16))))))))
  43.   (format t "~{~a~}~%" (mapcar #'bit-smasher:bits->hex denseh)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement