From 6d754b0312bdf9a7550e6fa9bd6bdec9a66fd109 Mon Sep 17 00:00:00 2001 From: Lowl3v3l Date: Tue, 9 May 2017 19:17:20 +0200 Subject: [PATCH] some racket solutions to show the folder structure --- 14/euler14.rkt | 18 ++++++++++++++++++ 25/euler25.rkt | 11 +++++++++++ 2 files changed, 29 insertions(+) create mode 100644 14/euler14.rkt create mode 100644 25/euler25.rkt 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