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.

47 lines
1.0 KiB

#+title: solution to p11
#+begin_src emacs-lisp :results none
(with-temp-buffer
(insert-file-contents "input")
(advent/replace-multiple-regex-buffer
'((":" . " ")
("^" . "(")
("$" . ")")))
(goto-char (point-min))
(insert "(setq data '(")
(goto-char (point-max))
(insert "))")
(eval-buffer))
#+end_src
This is for part 1
#+begin_src emacs-lisp
(defun paths-from (label)
(if (eq label 'out) 1
(-sum (-map 'paths-from (cdr (assq label data))))))
(memoize 'paths-from)
(paths-from 'you)
#+end_src
#+RESULTS:
: 701
And this for part 2; note that there are no paths from dac to fft
(there can be only paths in one direction, otherwise we would get
a loop.
#+begin_src emacs-lisp
(defun paths-from-to (label exit)
(if (eq label exit) 1
(if (eq label 'out) 0
(-sum (--map (paths-from-to it exit) (cdr (assq label data)))))))
(memoize 'paths-from-to)
(* (paths-from-to 'svr 'fft)
(paths-from-to 'fft 'dac)
(paths-from 'dac))
#+end_src
#+RESULTS:
: 390108778818526