Anonymous user
Set consolidation: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments, used a template for the output section.
m (→{{header|REXX}}: added/changed whitespace and comments, used a template for the output section.) |
|||
Line 2,061:
=={{header|REXX}}==
<lang rexx>/*REXX program
@.=; @.1 = '{A,B} {C,D}'
@.2 = "{A,B} {B,D}"
@.3 = '{A,B} {C,D} {D,B}'
@.4 = '{H,I,K} {A,B} {C,D} {D,B} {F,G,H}'
@.5 = '{snow,ice,slush,frost,fog} {icebergs,icecubes} {rain,fog,sleet}'
exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
isIn: return wordpos(arg(1), arg(2))\==0 /*is (word) argument 1 in the set arg2?*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
SETconsolidate: procedure; parse arg old; #= words(old); new=
say ' the old set=' space(old)
do k=1 for # /* [↓] change all commas to a blank. */
!.k= translate( word(old, k), , '},{')
end /*k*/ /* [↑] ··· and also remove the braces.*/
do until \changed; changed=
do set=1 for #-1
do item=1 for words(!.set); x= word(!.set, item)
do other=set+1 to #
if isIn(x, !.other) then do; changed=
!.set= !.set !.other; !.other=
iterate set
end
Line 2,095:
end /*until ¬changed*/
do set=1 for #;
do items=1 for words(!.set); x= word(!.set, items)
if x==',' then iterate; if x=='' then leave
$= $ x
do until \isIn(x, !.set)
_= wordpos(x, !.set)
!.set= subword(!.set, 1, _-1)
end /*until ¬isIn ··· */
end /*items*/
!.set= translate( strip($), ',', " ")
end /*set*/
do i=1 for #; if !.i=='' then iterate /*ignore any set that is a null set. */
new= space(new '{'!.i"}")
end /*i*/
say ' the new set=' new; say
return</lang>
<pre>
the old set= {A,B} {C,D}
|