summaryrefslogtreecommitdiff
path: root/euler4.scm
diff options
context:
space:
mode:
Diffstat (limited to 'euler4.scm')
-rw-r--r--euler4.scm20
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)
+