Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,29 @@
|
|||
;; using srfi-69
|
||||
(define (memoize proc)
|
||||
(let ((results (make-hash-table)))
|
||||
(lambda args
|
||||
(or (hash-table-ref results args (lambda () #f))
|
||||
(let ((r (apply proc args)))
|
||||
(hash-table-set! results args r)
|
||||
r)))))
|
||||
|
||||
(define (longest xs ys)
|
||||
(if (> (length xs)
|
||||
(length ys))
|
||||
xs ys))
|
||||
|
||||
(define lcs
|
||||
(memoize
|
||||
(lambda (seqx seqy)
|
||||
(if (pair? seqx)
|
||||
(let ((x (car seqx))
|
||||
(xs (cdr seqx)))
|
||||
(if (pair? seqy)
|
||||
(let ((y (car seqy))
|
||||
(ys (cdr seqy)))
|
||||
(if (equal? x y)
|
||||
(cons x (lcs xs ys))
|
||||
(longest (lcs seqx ys)
|
||||
(lcs xs seqy))))
|
||||
'()))
|
||||
'()))))
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
(test-group
|
||||
"lcs"
|
||||
(test '() (lcs '(a b c) '(A B C)))
|
||||
(test '(a) (lcs '(a a a) '(A A a)))
|
||||
(test '() (lcs '() '(a b c)))
|
||||
(test '() (lcs '(a b c) '()))
|
||||
(test '(a c) (lcs '(a b c) '(a B c)))
|
||||
(test '(b) (lcs '(a b c) '(A b C)))
|
||||
|
||||
(test '( b d e f g h j)
|
||||
(lcs '(a b d e f g h i j)
|
||||
'(A b c d e f F a g h j))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue