You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

1.4 KiB

Solution for p11

  (setq data '(125 17))
125 17

Define the auxiliary functions

  (defun number-digits (x)
    (1+ (floor (log x 10))))

  (defun split (x)
    (let* ((n (number-digits x))
           (div (expt 10 (/ n 2))))
      (--map (funcall it x div) '(/ %))))

  (defun blink (x)
    (cond
     ((eq x 0) '(1))
     ((eq (% (number-digits x) 2) 0) (split x))
     (t (list (* 2024 x)))))
blink

And now compute. For the first step a simple implementation suffices

  (length (-last-item  (--iterate (-mapcat #'blink it) data (1+ 25))))
194482

Otherwise, we need to be smarter. We group Peebles in piles with the same engraving and blink only once for each group

  (setq freq-data (-frequencies data))

  (defun regroup (l)
    (-map (lambda (el) (cons el  (-reduce #'+ (-map #'cdr (--filter (eq el (car it)) l)))))  (-distinct (-map #'car l))))

  (--reduce-from (+ acc (cdr it)) 0 (-last-item (--iterate (regroup (-mapcat (lambda (a)
                                                         (--map (cons it (cdr a))
                                                                (blink (car a)))) it))
                                     freq-data (1+ 75))))
232454623677743