From 30eec69d68dc72e55ec9f9efefa667885e8dbcce Mon Sep 17 00:00:00 2001 From: Jacopo De Simoi Date: Wed, 9 Apr 2025 23:50:23 -0400 Subject: [PATCH] =?UTF-8?q?This=20should=20work=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It seems very inefficient, though --- p11/p11.org | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 p11/p11.org 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)