Lisp Cyclic Rotation
(defun cyclic-rotation (a k)
(if (null a)
a
(let ((result (copy-list a)))
(dotimes (i k)
(let ((last (car (last result))))
(setf result (cons last (butlast result)))))
result)))
This rotates the array to the right by K steps and keeps the wrap-around values in the correct order.