aboutsummaryrefslogtreecommitdiff
path: root/0004/main.lisp
blob: 8874489493130fb445ed5165e1dd6974f4546059 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
(defun find-palindrome-impl (i j current-max)
    (cond ((> j 999) current-max)
	  ((> i 999) (find-palindrome-impl 100 (+ j 1) current-max))
	  ((is-palindrome (* i j))
	   (if (> (* i j) current-max)
	       (find-palindrome-impl (+ i 1) j (* i j))
	       (find-palindrome-impl (+ i 1) j current-max)))
	  (t (find-palindrome-impl (+ i 1) j current-max))))

(defun is-palindrome (x)
  (equal (reverse (write-to-string x)) (write-to-string x)))


(format t "~&~S~%" (find-palindrome-impl 100 100 0))