[p21] part 2 done

comments need improvement
main
Jacopo De Simoi 6 months ago
parent b5bc48128b
commit caff3298d2
  1. 13
      p21/p21.org

@ -163,15 +163,15 @@ So we start from all possible combinations of keypad pairs
(-mapcat (lambda (x) (--map (cons x it) directions)) directions)))
(setq basis-induction
(--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) )
first-step (--map (cons (car it) (length (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)))))
(apply #'+ (--map (cdr (assoc it al)) (split-into-char-pairs (concat "A" s)))))
(defun iterate-step (l)
(--map (cons (car it) (pick-shortest-string
(--map (cons (car it) (-min
(--map (iterate-robot it l) (cdr it))))
basis-induction))
@ -180,8 +180,8 @@ So we start from all possible combinations of keypad pairs
(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)))))
(apply '+ (--map (-min (--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))
@ -191,3 +191,6 @@ So we start from all possible combinations of keypad pairs
;oh, it does…
#+end_src
#+RESULTS:
: 271397390297138

Loading…
Cancel
Save