Advertisement
krzysz00

Advent of code, day 17

Dec 17th, 2017
121
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defun new-circ (value)
  2.   (let ((head (cons value nil)))
  3.     (setf (cdr head) head)
  4.     head))
  5.  
  6. (defun ninsert-after-and-move (list i)
  7.   (let ((new-cons (cons i (cdr list))))
  8.     (setf (cdr list) new-cons)
  9.     new-cons))
  10.  
  11. (defconstant +N-ITERATIONS-A+ 2017)
  12. (defconstant +N-ITERATIONS-B+ 50000000)
  13. (defconstant +N-STEPS+ 345)
  14.  
  15. (defun solve (n)
  16.   (let ((list (new-circ 0)))
  17.     (loop for i from 1 to n do
  18.          (loop for j from 1 to +N-STEPS+ do
  19.               (setf list (cdr list)))
  20.          (setf list (ninsert-after-and-move list i))
  21.          (if (= (mod i 200000) 0) (format t "~a~%" i)))
  22.     list))
  23.  
  24. (defun cons-with-elem (list elem)
  25.   (loop
  26.      (if (= (car list) elem) (return list)
  27.          (setf list (cdr list)))))
  28.  
  29. (format t "~a~%" (cadr (solve +N-ITERATIONS-A+)))
  30. (format t "~a~%" (cadr (cons-with-elem (solve +N-ITERATIONS-B+) 0)))
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement