day 11 part 2, yay
This commit is contained in:
@@ -172,7 +172,8 @@
|
||||
(defparameter *test-monkey-instance*
|
||||
(make-instance 'monkey
|
||||
:test (lambda (num) (if (= num 4) 9 8)) :operation (lambda (num) (+ num 1))
|
||||
:inventory '(100 60 30) :number 4))
|
||||
:inventory '(100 60 30) :number 4
|
||||
:mod 5))
|
||||
(monkey-one-item-action *test-monkey-instance*)
|
||||
(inspection-counter *test-monkey-instance*)
|
||||
|
||||
@@ -222,3 +223,51 @@
|
||||
;; now. if i read in all those "divisible by" so. what i want is to preserve MOD x
|
||||
;; so, could get lowest common multiple and get mod from that? and set it in all monkeys,
|
||||
;; or better - define it as class \ static attribute
|
||||
|
||||
(defparameter *11-input-paragraphs*
|
||||
(cl-ppcre:split "\\n\\n" (uiop:read-file-string "day11-input.txt")))
|
||||
|
||||
(defparameter *11-input-structs* nil)
|
||||
(defparameter *11-input-structs*
|
||||
(coerce (mapcar #'monkey-struct-to-instance
|
||||
(mapcar #'line-to-sexp *11-input-paragraphs*)) 'vector))
|
||||
|
||||
(loop
|
||||
for monkey across *11-input-structs*
|
||||
do (when (not (= 0 (mod (mod-reductor-2 monkey) (monkey-mod monkey))))
|
||||
(setf (slot-value monkey 'mod-reductor-2) (* (mod-reductor-2 monkey) (monkey-mod monkey)))))
|
||||
|
||||
(mod 1 3)
|
||||
(setf (slot-value *test-monkey-instance* 'mod-reductor-2) 1)
|
||||
;; yep.
|
||||
;; now need to take mod by this one? and then it will preserve mod by any of previous, right?
|
||||
|
||||
(mod (+ 9699690 177) 5)
|
||||
(mod 177 5)
|
||||
;; now substitute my worry by mod over "common multiple" and run 20k cycles
|
||||
(mod 4 7)
|
||||
|
||||
(progn
|
||||
(defparameter *11-test-input* (cl-ppcre:split "\\n\\n" (uiop:read-file-string "day11-test.txt")))
|
||||
(defparameter *11-test-structs*
|
||||
(coerce (mapcar #'monkey-struct-to-instance
|
||||
(mapcar #'line-to-sexp *11-test-input*)) 'vector))
|
||||
;; oh, i need to reset and recalculate the lowest common multiple for test input.
|
||||
;; yup
|
||||
(setf (slot-value *test-monkey-instance* 'mod-reductor-2) 1)
|
||||
(loop
|
||||
for monkey across *11-test-structs*
|
||||
do (when (not (= 0 (mod (mod-reductor-2 monkey) (monkey-mod monkey))))
|
||||
(setf (slot-value monkey 'mod-reductor-2) (* (mod-reductor-2 monkey) (monkey-mod monkey)))))
|
||||
|
||||
(loop
|
||||
for i from 1 to 10000
|
||||
do (progn (monkeys-round *11-test-structs*)
|
||||
(format t "turn ~a~%" i)))
|
||||
|
||||
(print (apply #'* (subseq (sort
|
||||
(mapcar #'inspection-counter
|
||||
(coerce *11-test-structs* 'list)) #'>) 0 2)))
|
||||
(setf (slot-value *test-monkey-instance* 'mod-reductor-2) 1))
|
||||
|
||||
;; yeah
|
||||
|
||||
Reference in New Issue
Block a user