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))
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
(define H27 (iterator/f hailstone 27))
|
||||
(take H27 6)
|
||||
→ (27 82 41 124 62 31)
|
||||
(length H27)
|
||||
→ 112
|
||||
(list-tail (take H27 112) -6)
|
||||
→ (5 16 8 4 2 1)
|
||||
|
||||
(task)
|
||||
maxlength= 351 for 77031
|
||||
|
||||
;; more ...
|
||||
(lib 'bigint)
|
||||
|
||||
(task 200000)
|
||||
maxlength= 383 for 156159
|
||||
(task 300000)
|
||||
maxlength= 443 for 230631
|
||||
(task 400000)
|
||||
maxlength= 443 for 230631
|
||||
(task 500000)
|
||||
maxlength= 449 for 410011
|
||||
(task 600000)
|
||||
maxlength= 470 for 511935
|
||||
(task 700000)
|
||||
maxlength= 509 for 626331
|
||||
(task 800000)
|
||||
maxlength= 509 for 626331
|
||||
(task 900000)
|
||||
maxlength= 525 for 837799
|
||||
(task 1000000)
|
||||
maxlength= 525 for 837799
|
||||
Loading…
Add table
Add a link
Reference in a new issue