Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #59683

Rosetta Code: Longest common subsequence

From "Robert L." <No_spamming@noWhere_7073.org>
Newsgroups comp.lang.forth
Subject Rosetta Code: Longest common subsequence
Date 2017-05-21 18:28 +0000
Organization Aioe.org NNTP Server
Message-ID <ofsm9a$mnd$1@gioia.aioe.org> (permalink)

Show all headers | View raw


> The longest common subsequence (or LCS) of groups A and B is
> the longest group of elements from A and B that are common
> between the two groups and in the same order in each group.
> For example, the sequences "1234" and "1224533324" have an LCS
> of "1234":

> For a string example, consider the sequences "thisisatest" and
> "testing123testing". An LCS would be "tsitest":

> In this puzzle, your code only needs to deal with strings.
> Write a function which returns an LCS of two strings
> (case-sensitive). You don't need to show multiple LCS's.


(use util.lcs)

(define (string-lcs . args)
  (list->string (apply lcs (map string->list args))))

(string-lcs "thisisatest" "testing123testing")
 ===>
"tsitest"


(string-lcs "1234" "1224533324")
 ===>
"1234"


(string-lcs "123456" "1a2b3c")
 ===>
"123"


(string-lcs "rosettacode" "raisethysword")
 ===>
"rsetod"


-- 
Germany: Afghan Migrants Force Teen Boy To Perform Oral Sex at Swimming Pool.
The Afghan men, aged 20 and 25, are said to have cornered the 14-year-old in
the showers, where they forced him to perform sexual acts on both of them.
infostormer.com/germany-afghan-migrants-force-teen-boy-to-perform-oral-sex-at-swimming-pool

Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread


Thread

Rosetta Code: Longest common subsequence "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-21 18:28 +0000

csiph-web