This should work…

It seems very inefficient, though
main
Jacopo De Simoi 11 months ago
parent 4fb205daf8
commit 30eec69d68
  1. 37
      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)
Loading…
Cancel
Save