diff options
author | Grant Shangreaux <grant@unabridgedsoftware.com> | 2022-01-30 20:40:42 -0600 |
---|---|---|
committer | Grant Shangreaux <grant@unabridgedsoftware.com> | 2022-01-30 20:40:42 -0600 |
commit | 2b981fc945d9beded27b0ecff182f70c92c79b32 (patch) | |
tree | 3d58fbfb263bb234fd7af48b47e4cd4a29120924 | |
parent | af0f607cf8c7a4f34d138ee3bf9155269cfdc2f9 (diff) |
Clean: use mod in neighbors fun to be nicer
-rw-r--r-- | mafia.org | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -239,12 +239,13 @@ the list and see if the target is the killer. #+name: neighbors #+begin_src emacs-lisp - (defun neighbors (e lst) - (let* ((idx (seq-position lst e)) - (last-idx (1- (length lst))) - (left (if (zerop idx) last-idx (1- idx))) - (right (if (= idx last-idx) 0 (1+ idx)))) - (list (elt lst left) (elt lst right)))) + (defun neighbors (e lst) + (let* ((idx (cl-position e lst)) + (len (length lst)) + (left (elt lst (mod (1- idx) len))) + (right (elt lst (mod (1+ idx) len)))) + + (list left right))) #+end_src #+name: being-watched? |