Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Signed-off-by: (Bit-Mage) <[email protected]>
  • Loading branch information
(Bit-Mage) committed Dec 11, 2024
1 parent 34a6eda commit 2eca596
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Content/20241202121706-advent_of_code_2024.org
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@
#+title: Advent of Code 2024
#+filetags: :project:

* Day 11
#+begin_src lisp
(ql:quickload :uiop)

(defparameter *stones* (uiop:split-string (uiop:read-file-line "input.txt")))

(defun even-str-p (string) (evenp (length string)))
(defun strip-string (stone) (write-to-string (parse-integer stone)))
(defun x2024 (stone) (write-to-string (* (parse-integer stone) 2024)))
(defun halves (string)
(let ((split (/ (length string) 2)))
(mapcar #'strip-string (list (subseq string 0 split) (subseq string split)))))

(defparameter *mem* (make-hash-table :test 'equal))
(defmacro ghsh (stone steps)
`(gethash (list ,stone ,steps) *mem*))

(defun nstep (stone steps)
(if (ghsh stone steps) (ghsh stone steps)
(setf (ghsh stone steps)
(cond ((= steps 0) 1)
((equal stone "0") (nstep "1" (1- steps)))
((even-str-p stone) (apply #'+ (mapcar #'(lambda (stone)
(nstep stone (1- steps)))
(halves stone))))
(t (nstep (x2024 stone) (1- steps)))))))

(defun solve (i)
(apply #'+ (mapcar #'(lambda (stone) (nstep stone i)) *stones*)))
#+end_src
* Day 10
#+begin_src lisp
(ql:quickload :uiop)
Expand Down

0 comments on commit 2eca596

Please sign in to comment.