racket solutions for 1 and 2

This commit is contained in:
Lowl3v3l 2017-05-09 19:20:46 +02:00
parent 6d754b0312
commit faf8f4962a
2 changed files with 23 additions and 0 deletions

10
1/euler1.rkt Normal file
View file

@ -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)

13
2/euler2.rkt Normal file
View file

@ -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 '())))