This repository has been archived on 2024-01-26. You can view files and clone it, but cannot push or open issues or pull requests.
project-euler/e0014/euler0014.rkt

12 lines
359 B
Racket
Raw Permalink Normal View History

#lang typed/racket
(: collatz (-> Nonnegative-Integer (Listof Nonnegative-Integer)))
(define (collatz x)
(cond
((equal? x 1) (list 1))
((even? x) (cons x (collatz (quotient x 2))))
((odd? x) (cons x (collatz (+ 1 (* 3 x)))))
(else (list))))
(argmax (λ ((x : Nonnegative-Integer)) (length (collatz x))) (range 1 1000000))