From 6908fb40dfecc925047ac8fd434f89257e1bd4e9 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Thu, 21 Jul 2022 16:07:18 -0500 Subject: [replace] permute-list with permute --- init-el.org | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/init-el.org b/init-el.org index 103dc5a..d7b48e9 100644 --- a/init-el.org +++ b/init-el.org @@ -1966,13 +1966,15 @@ messages echo to the echo area. (setq lifecoach-index 0) (setq permuted-lifecoach-messages nil) -(defun permute-list (ls) - "Will not work properly if there are duplicates in LS, as the - returned list will not have any duplicates" - (when ls - (let ((nth - (nth (random (length ls)) ls))) - (cons nth (permute-list (delete nth ls)))))) +(defun permute (seq) + (let ((len (length seq))) + (if (zerop len) + seq + (let ((idx + (random len))) + (append (subseq seq idx (1+ idx)) + (permute (append (subseq seq 0 idx) + (subseq seq (1+ idx))))))))) (defun lifecoach-message () (setq lifecoach-index @@ -1987,7 +1989,7 @@ messages echo to the echo area. (when lifecoach-idle-timer (cancel-timer lifecoach-idle-timer)) (setq - permuted-lifecoach-messages (permute-list (copy-seq lifecoach-messages)) + permuted-lifecoach-messages (permute (copy-seq lifecoach-messages)) lifecoach-idle-timer (run-with-idle-timer 30 t #'lifecoach-message))) (defun lifecoach-stop () -- cgit v1.2.3