summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2022-01-30 20:40:42 -0600
committerGrant Shangreaux <grant@unabridgedsoftware.com>2022-01-30 20:40:42 -0600
commit2b981fc945d9beded27b0ecff182f70c92c79b32 (patch)
tree3d58fbfb263bb234fd7af48b47e4cd4a29120924
parentaf0f607cf8c7a4f34d138ee3bf9155269cfdc2f9 (diff)
Clean: use mod in neighbors fun to be nicer
-rw-r--r--mafia.org13
1 files changed, 7 insertions, 6 deletions
diff --git a/mafia.org b/mafia.org
index 6ea93a9..8313615 100644
--- a/mafia.org
+++ b/mafia.org
@@ -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?