(defun factorial (n) (if (< n 2) 1 (* n (factorial (1- n)))) ) (defun primep (n) "Primality test using Wilson's Theorem" (unless (zerop n) (zerop (mod (1+ (factorial (1- n))) n)) )) (defun ispal (n) "Is integer n a palindrome?" (setq a (write-to-string n)) (return-from ispal (string-equal a (reverse a))) ) (defun char-to-int (char) (- (char-int char) (char-int #\0))) ; convert single char 0-9 to integer (defun sum-digits (list1) (setq sum1 0) (loop for item in list1 do (setq sum1 (+ (char-to-int item) sum1))) (return-from sum-digits sum1) ) (defun prime-sumdig-pal () (loop for cand from 10000 to 11000 do (progn (if (primep cand) (progn (setq l1 (write-to-string cand)) (setq list1 (coerce l1 'list)) (setq sum1 (sum-digits list1)) (if (ispal sum1) (print (list cand sum1))) ) ) ) ) )