Add ~coordinates-of~ to library

main
Jacopo De Simoi 6 months ago
parent 00f1c27433
commit 7b46cd6b6c
  1. 13
      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

Loading…
Cancel
Save