blob: 8cbc7c949cce72f71dbc604ab225f612ba7af9fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
;;;; ;;;;;;;;
;;;; Largest palindrome product
;;;; Problem 4
;;;;
;;;; A palindromic number reads the same both ways.
;;;; The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
;;;; Find the largest palindrome made from the product of two 3-digit numbers.
;;;; ;;;;;;;;
(defun palindrome-p (n)
(equal (write-to-string n) (reverse (write-to-string n))))
(print (palindrome-p 32))
(defvar *largest* 0)
(loop :for x :from 999 :downto 1 :do
(loop :for y :from 999 :downto 1 :do
(when (and (palindrome-p (* x y)) (> (* x y) *largest*))
(print (* x y))
(setf *largest* (* x y)))))
(print *largest*)
|