diff --git a/lib/lib-advent.org b/lib/lib-advent.org index 68e7ad8..e4cd225 100644 --- a/lib/lib-advent.org +++ b/lib/lib-advent.org @@ -19,3 +19,16 @@ "Split the string into a list of chars" (--map (string-to-char it) (split-string str "\\|.+" t))) #+end_src + + #+begin_src emacs-lisp + (defun advent/coordinates-of (e li) + "This takes a 2D list (a list of lists) of chars LI and an element E + and returns a list of positions in LI that contain the element E. + " + (-map #'cadr + (--filter (eq (car it) e) + (-mapcat #'identity + (-map-indexed (lambda (y l) + (-map-indexed (lambda (x el) (list el (list x y))) l)) + li))))) + #+end_src