From 1eefd58ca4fdb5d2f51f657bfd70c9a89a4707db Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Thu, 24 May 2018 21:39:58 +0800 Subject: initial commit --- euler4.scm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 euler4.scm (limited to 'euler4.scm') 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) + -- cgit v1.2.3