diff options
author | Iru Cai <mytbk920423@gmail.com> | 2018-05-24 21:39:58 +0800 |
---|---|---|
committer | Iru Cai <mytbk920423@gmail.com> | 2018-05-24 21:39:58 +0800 |
commit | 1eefd58ca4fdb5d2f51f657bfd70c9a89a4707db (patch) | |
tree | abde0e4da3c7fe138f3874a94d8eb7d0e44c3224 /euler4.scm | |
download | project_euler-1eefd58ca4fdb5d2f51f657bfd70c9a89a4707db.tar.xz |
initial commit
Diffstat (limited to 'euler4.scm')
-rw-r--r-- | euler4.scm | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/euler4.scm b/euler4.scm new file mode 100644 index 0000000..09408a9 --- /dev/null +++ b/euler4.scm @@ -0,0 +1,20 @@ +(define (palindrome? x) + (define (rev x ans) + (if (= x 0) + ans + (let ((r (remainder x 10))) + (rev (/ (- x r) 10) (+ r (* ans 10)))))) + (= (rev x 0) x)) + +(define (bigpal ans x y) + (if (> x 999) + ans + (if (> y 999) + (bigpal ans (+ x 1) (+ x 1)) + (if (and (palindrome? (* x y)) (> (* x y) ans)) + (bigpal (* x y) x (+ y 1)) + (bigpal ans x (+ y 1)))))) + +(display (bigpal 0 100 100)) +(newline) + |