[p11] Part 1 and 2 done

master^2
Jacopo De Simoi 3 months ago
parent b8c616b461
commit 551eec19db
  1. 47
      p11/p11.org

@ -0,0 +1,47 @@
#+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
Loading…
Cancel
Save