From 7b46cd6b6c163e652a9f3ec6aa9ae9299fc7d023 Mon Sep 17 00:00:00 2001 From: Jacopo De Simoi Date: Thu, 11 Sep 2025 10:35:43 -0400 Subject: [PATCH] Add ~coordinates-of~ to library --- lib/lib-advent.org | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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