Longest common subsequence: Difference between revisions

m
→‎{{header|Racket}}: Add string wrapper and example
(Updated third D entry)
m (→‎{{header|Racket}}: Add string wrapper and example)
Line 1,546:
 
=={{header|Racket}}==
<lang racket>#lang racket
#lang racket
(define (longest xs ys)
(if (> (length xs) (length ys))
Line 1,559 ⟶ 1,558:
r)
 
(define (lcs/list sx sy)
(or (lookup sx sy)
(store sx sy
Line 1,565 ⟶ 1,564:
[((cons x xs) (cons y ys))
(if (equal? x y)
(cons x (lcs/list xs ys))
(longest (lcs/list sx ys) (lcs/list xs sy)))]
[(_ _) '()]))))
 
</lang>
(define (lcs sx sy)
(list->string (lcs/list (string->list sx) (string->list sy))))
 
(lcs "thisisatest" "testing123testing")</lang>
{{out}}
<pre>"tsitest"></pre>
 
=={{header|REXX}}==
Anonymous user