Day 06 in Common Lisp optimalization
There's no need to rotate the array itself when you can just rotate an offset into the array.
This commit is contained in:
parent
16a6302e40
commit
f65e1232f6
|
@ -27,12 +27,9 @@
|
|||
|
||||
(defun solution (data days)
|
||||
(let ((working (preprocess-input data)))
|
||||
(dotimes (n days)
|
||||
(let ((zeroes (aref working 0)))
|
||||
(loop for x from 1 to 8
|
||||
do (setf (aref working (1- x)) (aref working x)))
|
||||
(setf (aref working 8) zeroes)
|
||||
(setf (aref working 6) (+ zeroes (aref working 6)))))
|
||||
(dotimes (offset (1+ days))
|
||||
(setf (aref working (mod (+ offset 6) 9)) (+ (aref working (mod (+ offset 8) 9))
|
||||
(aref working (mod (+ offset 6) 9)))))
|
||||
(loop for x from 0 to 8 sum (aref working x))))
|
||||
|
||||
(defun part1 (data)
|
||||
|
|
Reference in New Issue