34 lines
870 B
Text
34 lines
870 B
Text
function has_intersection(sequence set1, sequence set2)
|
|
for i=1 to length(set1) do
|
|
if find(set1[i],set2) then
|
|
return true
|
|
end if
|
|
end for
|
|
return false
|
|
end function
|
|
|
|
function union(sequence set1, sequence set2)
|
|
for i=1 to length(set2) do
|
|
if not find(set2[i],set1) then
|
|
set1 = append(set1,set2[i])
|
|
end if
|
|
end for
|
|
return set1
|
|
end function
|
|
|
|
function consolidate(sequence sets)
|
|
for i=length(sets) to 1 by -1 do
|
|
for j=length(sets) to i+1 by -1 do
|
|
if has_intersection(sets[i],sets[j]) then
|
|
sets[i] = union(sets[i],sets[j])
|
|
sets[j..j] = {}
|
|
end if
|
|
end for
|
|
end for
|
|
return sets
|
|
end function
|
|
|
|
?consolidate({"AB","CD"})
|
|
?consolidate({"AB","BD"})
|
|
?consolidate({"AB","CD","DB"})
|
|
?consolidate({"HIK","AB","CD","DB","FGH"})
|