Set consolidation: Difference between revisions

Add SETL
m (→‎{{header|Quackery}}: simplified code)
(Add SETL)
Line 2,578:
{A,B} {C,D} {D,B} -> {C,D,A,B}
{D,B} {F,G,H} {A,B} {C,D} {H,I,K} -> {F,I,G,H,K} {A,B,C,D}</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program set_consolidation;
tests := [
{{'A','B'}, {'C','D'}},
{{'A','B'}, {'B','D'}},
{{'A','B'}, {'C','D'}, {'D','B'}},
{{'H','I','K'}, {'A','B'}, {'C','D'}, {'D','B'}, {'F','G','H'}}
];
 
loop for t in tests do
print(consolidate(t));
end loop;
 
proc consolidate(sets);
outp := {};
loop while sets /= {} do
set_ from sets;
loop until overlap = {} do
overlap := {s : s in sets | exists el in s | el in set_};
set_ +:= {} +/ overlap;
sets -:= overlap;
end loop;
outp with:= set_;
end loop;
return outp;
end proc;
end program;</syntaxhighlight>
{{out}}
<pre>{{A B} {C D}}
{{A B D}}
{{A B C D}}
{{A B C D} {F G H I K}}</pre>
 
=={{header|Sidef}}==
2,119

edits