Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,28 @@
|
|||
(lib 'hash)
|
||||
(lib 'sequences)
|
||||
(lib 'compile)
|
||||
|
||||
(define (hailstone n)
|
||||
(when (> n 1)
|
||||
(if (even? n) (/ n 2) (1+ (* n 3)))))
|
||||
|
||||
(define H (make-hash))
|
||||
|
||||
;; (iterator/f seed f) returns seed, (f seed) (f(f seed)) ...
|
||||
|
||||
(define (hlength seed)
|
||||
(define collatz (iterator/f hailstone seed))
|
||||
(or
|
||||
(hash-ref H seed) ;; known ?
|
||||
(hash-set H seed
|
||||
(for ((i (in-naturals)) (h collatz))
|
||||
;; add length of subsequence if already known
|
||||
#:break (hash-ref H h) => (+ i (hash-ref H h))
|
||||
(1+ i)))))
|
||||
|
||||
(define (task (nmax 100000))
|
||||
(for ((n [1 .. nmax])) (hlength n)) ;; fill hash table
|
||||
|
||||
(define hmaxlength (apply max (hash-values H)))
|
||||
(define hmaxseed (hash-get-key H hmaxlength))
|
||||
(writeln 'maxlength= hmaxlength 'for hmaxseed))
|
||||
Loading…
Add table
Add a link
Reference in a new issue