diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-04-07 17:20:43 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-04-07 17:20:43 +0200 |
| commit | 9af65c8ac721024d0e45a2a6bde5c3f9fe638516 (patch) | |
| tree | e9af93ce9e4d0263b2e76d2fd29ada90d313f334 /lisp/004-largest_palindrome_product.lisp | |
| parent | 31b43cf6d0d58812d30c0e2356f6458d06b1e52e (diff) | |
| download | project_euler-9af65c8ac721024d0e45a2a6bde5c3f9fe638516.tar.gz project_euler-9af65c8ac721024d0e45a2a6bde5c3f9fe638516.tar.bz2 project_euler-9af65c8ac721024d0e45a2a6bde5c3f9fe638516.zip | |
problem 1 2 4 in common lisp
Diffstat (limited to 'lisp/004-largest_palindrome_product.lisp')
| -rw-r--r-- | lisp/004-largest_palindrome_product.lisp | 23 |
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*) |
