Set consolidation: Difference between revisions
J implementation
(→{{header|Ada}}: Added Ada version) |
(J implementation) |
||
Line 350:
[map[A:true C:true B:true D:true] map[G:true F:true I:true H:true K:true]]
</pre>
=={{header|J}}==
<lang J>consolidate=:4 :0/
b=. y 1&e.@e.S:_1 x
if. 0 e. b do. (~.;x,b#y);(-.b)#y
else. ,<~.;x,b#y end.
)</lang>
Examples:
<lang J> consolidate 'ab';'cd'
┌──┬──┐
│ab│cd│
└──┴──┘
consolidate 'ab';'bd'
┌───┐
│abd│
└───┘
consolidate 'ab';'cd';'db'
┌────┐
│abcd│
└────┘
consolidate 'hij';'ab';'cd';'db';'fgh'
┌─────┬────┐
│hijfg│abcd│
└─────┴────┘</lang>
=={{header|OCaml}}==
|