A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
|
|
@ -0,0 +1,21 @@
|
|||
#lang racket
|
||||
(define (longest xs ys)
|
||||
(if (> (length xs) (length ys))
|
||||
xs ys))
|
||||
|
||||
(define memo (make-hash))
|
||||
(define (lookup xs ys)
|
||||
(hash-ref memo (cons xs ys) #f))
|
||||
(define (store xs ys r)
|
||||
(hash-set! memo (cons xs ys) r)
|
||||
r)
|
||||
|
||||
(define (lcs sx sy)
|
||||
(or (lookup sx sy)
|
||||
(store sx sy
|
||||
(match* (sx sy)
|
||||
[((cons x xs) (cons y ys))
|
||||
(if (equal? x y)
|
||||
(cons x (lcs xs ys))
|
||||
(longest (lcs sx ys) (lcs xs sy)))]
|
||||
[(_ _) '()]))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue