Add docstrings

This commit is contained in:
Bram Schoenmakers 2023-06-18 20:21:18 +02:00
parent d062bb58bf
commit a81cb30df1

View file

@ -13302,12 +13302,13 @@ Figure out which monkeys to chase by counting how many items they inspect over 2
:type integer)))
(defun advent/11/parse-expression (expression)
"Parses the EXPRESSION and returns a callable."
"Parse the EXPRESSION and return a callable."
(let ((split-expr (split-string expression " ")))
(cl-destructuring-bind (op1 operator op2) split-expr
(read (format "(lambda (old) (%s %s %s))" operator op1 op2)))))
(defun advent/11/parse-input (input worry-drop)
"Parse the INPUT, store the amount of WORRY-DROP for each instantiated monkey."
(mapcar (lambda (s) (monkey
:number (string-to-number (nth 1 s))
:queue (mapcar #'string-to-number (split-string (nth 2 s) ", "))
@ -13328,13 +13329,15 @@ Figure out which monkeys to chase by counting how many items they inspect over 2
input)))
(cl-defmethod queue-item ((m monkey) item)
"Add ITEM to the monkey's M queue."
(let ((queue (oref m :queue)))
(setf (oref m :queue) (append queue (list item)))))
(cl-defmethod process-queue ((m monkey))
"Let the monkey examine the item according to the specification,
returns a cons cell specifying which monkey should receive
the item with the updated worry level."
"Let the monkey M examine the item according to the specification.
Returns a cons cell specifying which monkey should receive the
item with the updated worry level."
(named-let process-item ((result nil))
(if (oref m :queue)
(let* ((item (pop (oref m :queue)))
@ -13349,6 +13352,7 @@ Figure out which monkeys to chase by counting how many items they inspect over 2
result)))
(defun advent/11/perform-rounds (monkeys rounds)
"Perform number of ROUNDS on the list of MONKEYS."
(let* ((dividers (mapcar (lambda (m) (oref m :divider)) monkeys))
(lcm (-reduce #'* dividers)))
(dotimes (i rounds)
@ -13360,6 +13364,11 @@ Figure out which monkeys to chase by counting how many items they inspect over 2
monkeys))
(defun advent/11/count-most-active-monkeys (input rounds &optional worry-drop)
"Counts the most active monkeys based for the given number of ROUNDS on INPUT.
Because each the amount of worry to drop depends, it can be given
as a parameter and is stored along with each instantiated monkey
from the input."
(let* ((monkeys (advent/11/parse-input input
(or worry-drop 3)))
(sorted-monkeys (sort