Here’s my version of palindrome for lisp problems 99 no 06 found here
(defun last1 (lst) (car (last lst))) (defun palin1 (lst) (if (equal nil lst) t (let ((start (first lst)) (finish (last1 lst))) (if (equal start finish) (palin1 (rest (butlast lst))) nil))))
nice
Good job!:) Saved me a lot of nerves, I was going on the same idea but sort of got lost between parentheses š
an iterative approach
(defun make-palindrome(list)
(if (= (length list) 1)
list
(dotimes (count (length list) list)
(setf list (append list (list (nth (- (length list) (+ count (+ count 1))) list))))
))
)
A solution using mapcar and reduce
(defun is-palindrome (lst)
(reduce #'(lambda (x y) (if (and x y) t nil))
(mapcar #’eql lst (reverse lst))))
Shorter:
(defun palindrome(list)
(equal list (revers list)))