Anonymous user
Set consolidation: Difference between revisions
m
→{{header|REXX}}: changed/added comments and whitespace, changed a DO FOREVER loop into a DO UNTIL.
m (→{{header|REXX}}: removed STYLE from the PRE html tag.) |
m (→{{header|REXX}}: changed/added comments and whitespace, changed a DO FOREVER loop into a DO UNTIL.) |
||
Line 1,374:
=={{header|REXX}}==
<lang rexx>/*REXX program
sets.
sets.1 = '{A,B} {C,D}'
sets.2 = "{A,B} {B,D}"
Line 1,382:
sets.5 = '{snow,ice,slush,frost,fog} {iceburgs,icecubes} {rain,fog,sleet}'
do j=1 while sets.j\==''
call SETcombo sets.j /*have the other guy do the work.*/
end /*j*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────SETcombo subroutine─────────────────*/
SETcombo: procedure; parse arg bunch; n=words(bunch); newBunch=
say ' the old sets=' space(bunch)
do k=1 for n
@.k=translate(word(bunch,k),,'},{') /*create a list of words (=a set)*/
end
do until \changed; changed=0
do set=1 for n-1
do item=1 for words(@.set); x=word(@.set,item)
do other=set+1 to n
if isIn(x,@.other) then do; changed=1 /*has changed.*/
@.set=@.set @.other; @.other=
iterate set
end
end /*other*/
end /*item*/
Line 1,407:
end /*until ¬changed*/
do set=1 for n; new=
do items=1 for words(@.set); x=word(@.set, items)
new=new x /*start building the new set. */
do
_=wordpos(x, @.set)
@.set=subword(@.set,1,_-1) ',' subword(@.set,_+1) /*purify set.*/
end /*
end /*items*/
@.set=translate(strip(new), ',', " ")
end /*set*/
do new=1 for n; if @.new=='' then iterate
newBunch=space(newbunch '{'@.new"}")
end /*new*/
Line 1,425:
say ' the new sets=' newBunch; say
return
/*
isIn: return wordpos(arg(1), arg(2))\==0
'''output''' when using the default supplied sample sets:
<pre>
|