Set consolidation: Difference between revisions
Content added Content deleted
m (→{{header|Ada}}: Fixed typo (ect. → etc.)) |
(Add Factor) |
||
Line 814:
seq [set ["A"; "B"; "C"; "D"]]
seq [set ["A"; "B"; "C"; "D"]; set ["F"; "G"; "H"; "I"; "K"]]</pre>
=={{header|Factor}}==
<lang factor>USING: arrays kernel sequences sets ;
DEFER: comb
: (comb) ( x x -- x )
dup pick first intersects?
[ [ [ rest ] [ first ] bi ] dip union comb ]
[ [ [ first 1array ] [ rest ] bi ] dip comb append ] if ;
: comb ( x x -- x ) over empty? [ nip 1array ] [ (comb) ] if ;
: consolidate ( x -- x ) { } [ comb ] reduce ;</lang>
{{out}}
<pre>
IN: scratchpad USE: qw
IN: scratchpad qw{ AB CD } consolidate .
{ "AB" "CD" }
IN: scratchpad qw{ AB BC } consolidate .
{ "ABC" }
IN: scratchpad qw{ AB CD DB } consolidate .
{ "CDAB" }
IN: scratchpad qw{ HIK AB CD DB FGH } consolidate .
{ "CDAB" "HIKFG" }
</pre>
=={{header|Go}}==
|