diff --git a/14/euler14.rkt b/14/euler14.rkt new file mode 100644 index 0000000..ade1e42 --- /dev/null +++ b/14/euler14.rkt @@ -0,0 +1,18 @@ +#lang racket + +(define (longest-collatz n) + (let + ((pivot (list 0 0))) + (define (collatz lst) + (if (equal? (car lst) 1) + lst + (if (even? (car lst)) + (collatz (cons (quotient (car lst) 2) lst)) + (collatz (cons (+ 1 (* 3 (car lst))) lst))))) + (for ((i (range 1 n))) + (if (>= (length (collatz (list i))) (second pivot)) + (set! pivot (list i (length (collatz (list i))))) + 0)) + pivot)) + +(display (first (longest-collatz 1000000))) \ No newline at end of file diff --git a/25/euler25.rkt b/25/euler25.rkt new file mode 100644 index 0000000..876fc37 --- /dev/null +++ b/25/euler25.rkt @@ -0,0 +1,11 @@ +#lang racket + +(define (numdigits x) + (string-length (number->string x))) + +(define (fibs limit lst) + (if (equal? (numdigits (car lst)) limit) + (length lst) + (fibs limit (cons (+ (car lst) (cadr lst)) lst)))) + +(fibs 1000 '(1 1)) \ No newline at end of file