From 1701dc74ad5cf4a3467b9b404a7dbab8390c4ad4 Mon Sep 17 00:00:00 2001 From: Mistivia Date: Wed, 20 Nov 2024 20:13:16 +0800 Subject: 4 Largest Palindrome Product --- 0004/main.lisp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 0004/main.lisp diff --git a/0004/main.lisp b/0004/main.lisp new file mode 100644 index 0000000..8874489 --- /dev/null +++ b/0004/main.lisp @@ -0,0 +1,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)) -- cgit v1.0