From faf8f4962af7c871320e968822b6512c6deca87c Mon Sep 17 00:00:00 2001 From: Lowl3v3l Date: Tue, 9 May 2017 19:20:46 +0200 Subject: [PATCH] racket solutions for 1 and 2 --- 1/euler1.rkt | 10 ++++++++++ 2/euler2.rkt | 13 +++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 1/euler1.rkt create mode 100644 2/euler2.rkt diff --git a/1/euler1.rkt b/1/euler1.rkt new file mode 100644 index 0000000..8b116df --- /dev/null +++ b/1/euler1.rkt @@ -0,0 +1,10 @@ +#lang racket + +(define (multiples limit) + (foldl + 0 (filter (lambda (x) (cond + [(= 0 (remainder x 3)) #t] + [(= 0 (remainder x 5)) #t] + (else #f))) + (range limit)))) + +(multiples 1000) \ No newline at end of file diff --git a/2/euler2.rkt b/2/euler2.rkt new file mode 100644 index 0000000..2fc3525 --- /dev/null +++ b/2/euler2.rkt @@ -0,0 +1,13 @@ +#lang racket + +(define (fib i) + (cond [(equal? 0 i) 1] + [(equal? 1 i) 2] + (else (+ (fib (- i 1))(fib (- i 2)))))) + +(define (fiblist it limit lst) + (cond [(equal? limit it) lst] + (else (fiblist (+ it 1) limit + (cons (fib it) lst))))) + +(foldl + 0 (filter even? (fiblist 0 4000000 '()))) \ No newline at end of file