From 476da2e16311b381067fd8832712d9694fcc5228 Mon Sep 17 00:00:00 2001 From: Matteo Landi Date: Sat, 27 Jan 2024 15:45:28 +0100 Subject: [PATCH] Use memo function from utils --- src/2023/day12.lisp | 12 ------------ src/utils.lisp | 10 ++++++++++ 2 files changed, 10 insertions(+), 12 deletions(-) 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 ---------------------------------------------------------------------