| Faculty for Electrical Engineering and Informatics, BME
Engineering Programme in English |
MSc Course in Software Engineering
Autumn semester 2007/08
|
ts = [t0, t1, ...,
tz-1] where 0 ≤ z. If z = 0
then ts = []. Collect those pairs of words
(ti,tj) from ts for which,
with 0 ≤ i < z, 0 ≤ j < z, i
≠ j and 0 ≤ k, it is true that the last
k characters of ti are equal to the
first k characters of tj. In the
following, such pairs of words are called overlapping in k positions
or shortly k-overlapping. If k = 0 then
ti and tj do not
overlap.
More precisely: let us denote the characters of ti
by ci0
ci1 ...
cim-1 and the characters of
tj by cj0
cj1 ...
cjn-1. Then, the task is to produce all
those (ti,tj) pairs for which, with
0 ≤ k and i ≠ j, the conditions
cim-k = cj0,
cim-k+1 = cj1,
..., cim-1 = cjk-1
are all satisfied. If k = 0 then ti
and tj do not overlap.
Naturally, words that contain less than k characters must
not be enumerated.
overlappings to return the list
of all those k-overlapping pairs of strings (in any order) that are
produced by pairing the elements of a string list.
(* overlappings : int -> string list -> (string * string) list
overlappings k ts = the list of all k-overlapping pairs of elements from
ts
*)
overlappings 2 ["alma","omlik","mama","malom","ikra","atom","adat","ragad"] =
[("alma", "malom"), ("alma", "mama"), ("atom", "omlik"), ("omlik", "ikra"),
("malom", "omlik"), ("mama", "malom"), ("ikra", "ragad"),
("adat", "atom"), ("ragad", "adat")]
overlappings 3 ["alma","omlik","mama","malom","ikra","atom","adat","ragad"] =
[]
overlappings 1 ["alma","omlik","mama","malom","ikra","atom","adat","ragad"] =
[("alma", "adat"), ("alma", "atom"), ("ikra", "alma"), ("mama", "alma"),
("mama", "adat"), ("mama", "atom"), ("atom", "mama"), ("malom", "mama"),
("atom", "malom"), ("ikra", "adat"), ("ikra", "atom")]
overlappings 2 ["aa", "aa"] = [("aa", "aa"), ("aa", "aa")]
overlappings 3 ["aa", "aa"] = []