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.0 KiB
1.0 KiB
solution to p11
(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))
This is for part 1
(defun paths-from (label)
(if (eq label 'out) 1
(-sum (-map 'paths-from (cdr (assq label data))))))
(memoize 'paths-from)
(paths-from 'you)
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.
(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))
390108778818526