Advertisement
Guest User

Untitled

a guest
Jul 10th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.42 KB | None | 0 0
  1. (defun kth-to-last-recursive (l k)
  2.   (let ((i 0))
  3.     (labels ((helper (l)
  4.                (unless (null l)
  5.                  (let ((head (helper (rest l))))
  6.                    (incf i)
  7.                    (if (= i k)
  8.                        ;; how to return this and be done with recursion?
  9.                        (car l)
  10.                        head)))))
  11.       (helper l))))
  12. (= 5 (kth-to-last-recursive '(1 2 3 4 5) 1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement