Set consolidation: Difference between revisions
Content added Content deleted
m (→{{header|TXR}}: Drop @(do ...)) |
m (Added Sidef) |
||
Line 1,590: | Line 1,590: | ||
{A,B} {C,D} {D,B} -> {C,D,A,B} |
{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> |
{D,B} {F,G,H} {A,B} {C,D} {H,I,K} -> {F,I,G,H,K} {A,B,C,D}</pre> |
||
=={{header|Sidef}}== |
|||
{{trans|Perl 6}} |
|||
<lang ruby>func consolidate() { [] } |
|||
func consolidate(this, *those) { |
|||
gather { |
|||
consolidate(those...).each { |that| |
|||
if (this & that) { this |= that } |
|||
else { take that } |
|||
} |
|||
take this; |
|||
} |
|||
} |
|||
enum |A="A", B, C, D, _E, F, G, H, I, _J, K|; |
|||
func format(ss) { |
|||
ss.map{ '(' + .join(' ') + ')' }.join(' ') |
|||
} |
|||
[ |
|||
[[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]] |
|||
].each { |ss| |
|||
say (format(ss), "\n\t==> ", format(consolidate(ss...))); |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
(A B) (C D) |
|||
==> (C D) (A B) |
|||
(A B) (B D) |
|||
==> (A D B) |
|||
(A B) (C D) (D B) |
|||
==> (A C D B) |
|||
(H I K) (A B) (C D) (D B) (F G H) |
|||
==> (A C D B) (I K F G H) |
|||
</pre> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |