simplified

This commit is contained in:
Peter Tillemans 2024-12-11 09:08:31 +01:00
parent 8131259595
commit b8810a97a5

View file

@ -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