diff options
-rw-r--r-- | problem-4.scm | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/problem-4.scm b/problem-4.scm new file mode 100644 index 0000000..3622b5e --- /dev/null +++ b/problem-4.scm @@ -0,0 +1,23 @@ +(use-modules (srfi srfi-1) + (srfi srfi-42)) + +(define (products min max) + (list-ec (:range x min max) (:range y min max) (* x y))) + +(define (palindrome? x) + (define (test s) + (cond ((or (string-null? s) + (= (string-length s) 1)) + #t) + ((equal? (string-ref s 0) + (string-ref s (1- (string-length s)))) + (test (substring s 1 (1- (string-length s))))) + (else + #f))) + (let ((s (number->string x))) + (test s))) + +(define (palindrome-products min max) + (filter palindrome? (products min max))) + +(reduce max 0 (palindrome-products 100 1000)) |