I am trying to write a function which computes the length of the longest common subsequence of the two input strings str1 and str2. For example (LCS "scheme" "aheme") would return 4. I need some help getting started. Any ideas how to compute this?
I am also limited to the following built in function:
(read)
(cond)
(string-length x)
(string-ref str x)
(substring x y)
(string-append x y)
(equal? x y), (char=?)
(remainder x y), (quotient x y)
(max ...), (min ...)
This is what I have right now,
(define LCS
(lambda (str1 str2)
(if (OR (equal? str1 "") (equal? str2 ""))
0
(if (equal? (string-contains str1 (string-ref str2 0)) #t)
(+ 1 (LCS (substring str1 1 (string-length str1)) (substring str2 1 (string-length str2))))
(LCS (substring str1 1 (string-length str1)) (substring str2 1 (string-length str2)))))))
Where string-contains returns true if a string has a certain character in it. Right now it seems like it works but I think they may be a bug.