From b8810a97a5f874e0ce4449a3518cd41c5a8b40e3 Mon Sep 17 00:00:00 2001 From: Peter Tillemans Date: Wed, 11 Dec 2024 09:08:31 +0100 Subject: [PATCH] simplified --- src/2024/day11.lisp | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/src/2024/day11.lisp b/src/2024/day11.lisp index 4ff9fb1..e8cc1a5 100644 --- a/src/2024/day11.lisp +++ b/src/2024/day11.lisp @@ -42,30 +42,7 @@ (mod stone split-factor))) (t (list (* 2024 stone))))) ) -(defun evolve-stones (stones) - (loop for stone in stones - append (evolve-stone stone))) -(defun evolve-stones-n (stones n) - (loop for i from 1 to n - do (setf stones (evolve-stones stones)) - finally (return stones))) - -(defun number-stones-after-n-evolutions (stones n) - (length (evolve-stones-n stones n)) - ) - - -(defparameter stone-map-25-cache (make-hash-table :size 1000)) - -(defun map-stone-25 (stone) - (let ((rslt (gethash stone stone-map-25-cache))) - (or rslt - (let ((stones (evolve-stones-n (list stone) 25)) - (stone-map (make-hash-table))) - (loop for s in stones - do (incf (gethash s stone-map 0))) - (setf (gethash stone stone-map-25-cache) stone-map))))) (defun merge-stone-map (map1 map2 &optional (multiplier 1)) (let ((result (copy-hash-table map1))) @@ -76,14 +53,6 @@ result)) -(defun evolve-stone-map-25 (stone-map) - (let ((result (make-hash-table :size 1000))) - (loop - for k being the hash-keys of stone-map - for v being the hash-values of stone-map - do (setf result (merge-stone-map result (map-stone-25 k) v))) - result)) - (defun stones-to-stone-map (stones) (let ((result (make-hash-table :size (length stones)))) (loop