summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/06.lisp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/06.lisp b/src/06.lisp
new file mode 100644
index 0000000..8a7d2ec
--- /dev/null
+++ b/src/06.lisp
@@ -0,0 +1,37 @@
+(use-package 'cl-ppcre)
+(use-package 'trivia)
+
+(defun 06/parse-input-direct (input)
+ (mapcar #'parse-integer (split "," (car input))))
+
+(defun 06/parse-input (input-file)
+ (06/parse-input-direct (get-file-lines input-file)))
+
+(defun 06/one-iter (parsed-input)
+ (let* ((new 0)
+ (new-map (mapcar (lambda (x) (if (> x 0) (- x 1) (progn (incf new) 6))) parsed-input)))
+ (append new-map (make-list new :initial-element 8))))
+
+(defun 06/part-a (parsed-input)
+ (loop for i from 1 upto 80
+ do (setf parsed-input (06/one-iter parsed-input)))
+ (list-length parsed-input))
+
+(defun 06/another-iter (arr new)
+ (loop for i from 8 downto 0
+ for n = (aref arr i)
+ do (if (zerop i)
+ (progn
+ (setf (aref new 8) n)
+ (incf (aref new 6) n))
+ (setf (aref new (1- i)) n))))
+
+(defun 06/part-b (parsed-input)
+ (let ((initial (make-array 9 :initial-element 0))
+ (new (make-array 9)))
+ (dolist (i parsed-input) (incf (aref initial i)))
+ (loop for x below 256
+ do (progn (06/another-iter initial new)
+ (rotatef initial new)))
+ (apply #'+ (loop for x below 9
+ collect (aref initial x)))))