some racket solutions to show the folder structure
This commit is contained in:
parent
99ff80637c
commit
6d754b0312
2 changed files with 29 additions and 0 deletions
18
14/euler14.rkt
Normal file
18
14/euler14.rkt
Normal file
|
@ -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)))
|
11
25/euler25.rkt
Normal file
11
25/euler25.rkt
Normal file
|
@ -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))
|
Reference in a new issue