|
|
|
|
@ -165,13 +165,29 @@ So we start from all possible combinations of keypad pairs |
|
|
|
|
(--map (cons it (connecting-paths (char-pairs-to-coordinate-pairs it dir-keypad-data) dir-keypad-data)) direction-pairs) |
|
|
|
|
first-step (--map (cons (car it) (pick-shortest-string (cdr it))) basis-induction) ) |
|
|
|
|
|
|
|
|
|
; here first-step contains the keys that need to be pressed on the |
|
|
|
|
; human keypad to have the first keypad do as described |
|
|
|
|
(defun iterate-robot (s al) |
|
|
|
|
(apply #'concat (--map (cdr (assoc it al)) (split-into-char-pairs (concat "A" s))))) |
|
|
|
|
|
|
|
|
|
(defun iterate-step (l) |
|
|
|
|
(--map (cons (car it) (pick-shortest-string |
|
|
|
|
(--map (iterate-robot it l) (cdr it)))) |
|
|
|
|
basis-induction) |
|
|
|
|
) |
|
|
|
|
basis-induction)) |
|
|
|
|
|
|
|
|
|
; here iterate-step takes a list at step n and returns the same list |
|
|
|
|
; at step n+1 |
|
|
|
|
(setq last-step (funcall (-iteratefn 'iterate-step 24) first-step)) |
|
|
|
|
|
|
|
|
|
(defun shortest-stuff (s) |
|
|
|
|
(length (apply 'concat (--map (pick-shortest-string (--map (iterate-robot it last-step) it)) |
|
|
|
|
(directions-for-string s numeric-keypad-data))))) |
|
|
|
|
|
|
|
|
|
(defun complexity (s) |
|
|
|
|
(* (string-to-number (replace-in-string "A" "" s)) |
|
|
|
|
(shortest-stuff s))) |
|
|
|
|
|
|
|
|
|
(-reduce #'+ (-map #'complexity data)) |
|
|
|
|
|
|
|
|
|
;oh, it does… |
|
|
|
|
#+end_src |
|
|
|
|
|