17 lines
463 B
Common Lisp
17 lines
463 B
Common Lisp
;; Clear and concise
|
|
(defun palindromep (lst)
|
|
(equal lst (reverse lst)))
|
|
|
|
;; Alternative
|
|
(defun palindromep (lst)
|
|
(let* ((length-half (floor (length lst) 2))
|
|
(first-half (subseq lst 0 length-half))
|
|
(last-half (last lst length-half)))
|
|
(equal first-half (reverse last-half))))
|
|
|
|
;; C-c C-k
|
|
(assert (palindromep '(a b c d c b a)))
|
|
(assert (palindromep '(a b c c b a)))
|
|
(assert (not (palindromep '(a b c c b b))))
|
|
(assert (not (palindromep '(a b c d e))))
|