diff --git a/p11/p11.org b/p11/p11.org new file mode 100644 index 0000000..f6fa71f --- /dev/null +++ b/p11/p11.org @@ -0,0 +1,37 @@ +#+title: Solution for p11 + +#+begin_src emacs-lisp + (setq data '(0 27 5409930 828979 4471 3 68524 170)) +#+end_src + +#+RESULTS: +| 0 | 27 | 5409930 | 828979 | 4471 | 3 | 68524 | 170 | + +Define the auxiliary functions +#+begin_src emacs-lisp + (defun number-digits (x) + (1+ (floor (log x 10)))) + + (defun split (x) + (let ((n (number-digits x))) + (--map (funcall it x (expt 10 (/ n 2))) '(/ %)))) + + (defun blink (x) + (cond + ((eq x 0) '(1)) + ((eq (% (number-digits x) 2) 0) (split x)) + (t (list (* 2024 x))))) + #+end_src + + #+RESULTS: + : blink + +And now compute + #+begin_src emacs-lisp + (length (-last-item (--iterate (-mapcat #'blink it) data (1+ 75)))) + #+end_src + + #+RESULTS: + : 194482 + +(-mapcat #'blink data)