Jump to content

Set consolidation: Difference between revisions

m (→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations.)
Line 1,813:
AB,CD,DB = ABCD , - , -
HIK,AB,CD,DB,FGH = HIKFG , ABCD , - , - , -
</pre>
 
=={{header|zkl}}==
{{trans|Tcl}}
<lang zkl>fcn consolidate(sets){ // set are munged if they are read/write
if(sets.len()<2) return(sets);
r,r0 := List(List()),sets[0];
foreach x in (consolidate(sets[1,*])){
i,ni:=x.filter22(r0.holds); //-->(intersection, !intersection)
if(i) r0=r0.extend(ni);
else r.append(x);
}
r[0]=r0;
r
}
fcn prettize(sets){
sets.apply("concat"," ").pump(String,"(%s),".fmt)[0,-1]
}</lang>
<lang zkl>foreach sets in (T(
T(L("A","B")),
T(L("A","B"),L("C","D")),
T(L("A","B"),L("B","D")),
T(L("A","B"),L("C","D"),L("D","B")),
T(L("H","I","K"),L("A","B"),L("C","D"),L("D","B"),L("F","G","H")),
T(L("A","H"),L("H","I","K"),L("A","B"),L("C","D"),L("D","B"),L("F","G","H")),
T(L("H","I","K"),L("A","B"),L("C","D"),L("D","B"),L("F","G","H"), L("A","H")),
)){
prettize(sets).print(" --> ");
prettize(consolidate(sets)).println();
}</lang>
a{{out}}
<pre>
(A B) --> (A B)
(A B),(C D) --> (A B),(C D)
(A B),(B D) --> (A B D)
(A B),(C D),(D B) --> (A B C D)
(H I K),(A B),(C D),(D B),(F G H) --> (H I K F G),(A B C D)
(A H),(H I K),(A B),(C D),(D B),(F G H) --> (A H I K F G B C D)
(H I K),(A B),(C D),(D B),(F G H),(A H) --> (H I K A B C D F G)
</pre>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.