aboutsummaryrefslogtreecommitdiff
path: root/lisp/004-largest_palindrome_product.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/004-largest_palindrome_product.lisp')
-rw-r--r--lisp/004-largest_palindrome_product.lisp23
1 files changed, 23 insertions, 0 deletions
diff --git a/lisp/004-largest_palindrome_product.lisp b/lisp/004-largest_palindrome_product.lisp
new file mode 100644
index 0000000..8cbc7c9
--- /dev/null
+++ b/lisp/004-largest_palindrome_product.lisp
@@ -0,0 +1,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*)