RosettaCodeData/Task/Longest-common-subsequence/EasyLang/longest-common-subsequence.easy

18 lines
447 B
Text
Raw Permalink Normal View History

2024-03-06 22:25:12 -08:00
func$ right a$ n .
2024-07-13 15:19:22 -07:00
return substr a$ (len a$ - n + 1) n
2024-03-06 22:25:12 -08:00
.
func$ left a$ n .
2026-02-01 16:33:20 -08:00
if n < 0 : n = len a$ + n
2024-03-06 22:25:12 -08:00
return substr a$ 1 n
.
func$ lcs a$ b$ .
2026-02-01 16:33:20 -08:00
if len a$ = 0 or len b$ = 0 : return ""
if right a$ 1 = right b$ 1 : return lcs left a$ -1 left b$ -1 & right a$ 1
2024-03-06 22:25:12 -08:00
x$ = lcs a$ left b$ -1
y$ = lcs left a$ -1 b$
2026-02-01 16:33:20 -08:00
if len x$ > len y$ : return x$
return y$
2024-03-06 22:25:12 -08:00
.
print lcs "1234" "1224533324"
print lcs "thisisatest" "testing123testing"