diff --git a/package.lisp b/package.lisp index a32d8a6..5b69ba9 100644 --- a/package.lisp +++ b/package.lisp @@ -20,6 +20,7 @@ :_2 :partial-2 :defun/memo + :memoizing :with-complex-parts :complex-rotate-cw diff --git a/src/2023/day12.lisp b/src/2023/day12.lisp index fe19409..7dd9571 100644 --- a/src/2023/day12.lisp +++ b/src/2023/day12.lisp @@ -6,18 +6,6 @@ (list springs (extract-positive-integers groups)))) -(defmacro memoizing ((ht &rest key-parts) &body body) - (with-gensyms (memo key) - `(let ((,memo ,ht) - (,key (list ,@key-parts))) - (multiple-value-bind (res res?) (gethash ,key ,memo) - (if res? - res - (setf (gethash ,key ,memo) - (block memo - ,@body))))))) - - (defun count-valid-arrangements (s) (destructuring-bind (springs groups) (parse-condition-record s) (bnd1 (memo (make-hash-table :test 'equal)) diff --git a/src/utils.lisp b/src/utils.lisp index c2d1b8f..d03287a 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -356,6 +356,16 @@ `(defun ,clear-memo-name () (clrhash ,memo)))) +(defmacro memoizing ((ht &rest key-parts) &body body) + (with-gensyms (memo key) + `(let ((,memo ,ht) + (,key (list ,@key-parts))) + (multiple-value-bind (res res?) (gethash ,key ,memo) + (if res? + res + (setf (gethash ,key ,memo) + (block memo + ,@body))))))) ;;;; Math ---------------------------------------------------------------------