Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,14 @@
|
|||
#lang racket/base
|
||||
|
||||
(define r-cache (make-hash '((1 . 1) (2 . 3) (3 . 7))))
|
||||
(define s-cache (make-hash '((1 . 2) (2 . 4) (3 . 5) (4 . 6))))
|
||||
|
||||
(define (extend-r-s!)
|
||||
(define r-count (hash-count r-cache))
|
||||
(define s-count (hash-count s-cache))
|
||||
(define last-r (ffr r-count))
|
||||
(define new-r (+ (ffr r-count) (ffs r-count)))
|
||||
(hash-set! r-cache (add1 r-count) new-r)
|
||||
(define offset (- s-count last-r))
|
||||
(for ([val (in-range (add1 last-r) new-r)])
|
||||
(hash-set! s-cache (+ val offset) val)))
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
(define (ffr n)
|
||||
(hash-ref r-cache n (lambda () (extend-r-s!) (ffr n))))
|
||||
|
||||
(define (ffs n)
|
||||
(hash-ref s-cache n (lambda () (extend-r-s!) (ffs n))))
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
(displayln (map ffr (list 1 2 3 4 5 6 7 8 9 10)))
|
||||
(displayln (map ffs (list 1 2 3 4 5 6 7 8 9 10)))
|
||||
|
||||
(displayln "Checking for first 1000 integers:")
|
||||
(displayln (if (equal? (sort (append (for/list ([i (in-range 1 41)])
|
||||
(ffr i))
|
||||
(for/list ([i (in-range 1 961)])
|
||||
(ffs i)))
|
||||
<)
|
||||
(for/list ([i (in-range 1 1001)])
|
||||
i))
|
||||
"Test passed"
|
||||
"Test failed"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue