diff options
| author | Mistivia <i@mistivia.com> | 2024-11-20 20:13:16 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2024-11-20 20:13:16 +0800 |
| commit | 1701dc74ad5cf4a3467b9b404a7dbab8390c4ad4 (patch) | |
| tree | 534409bec21f5d3706c43e78d7e96f05b4f41c5d /0004/main.lisp | |
| parent | e685ad97fa257e2d6186eab66dc151f02ddc698c (diff) | |
4 Largest Palindrome Product
Diffstat (limited to '0004/main.lisp')
| -rw-r--r-- | 0004/main.lisp | 14 |
1 files changed, 14 insertions, 0 deletions
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)) |
