RosettaCodeData/Task/Remove-duplicate-elements/REXX/remove-duplicate-elements-1.rexx

12 lines
724 B
Rexx
Raw Permalink Normal View History

2017-09-23 10:01:46 +02:00
/*REXX program removes any duplicate elements (items) that are in a list (using a hash).*/
$= '2 3 5 7 11 13 17 19 cats 222 -100.2 +11 1.1 +7 7. 7 5 5 3 2 0 4.4 2' /*item list.*/
2013-04-10 23:57:08 -07:00
say 'original list:' $
2017-09-23 10:01:46 +02:00
say right( words($), 17, '') 'words in the original list.'
z=; @.= /*initialize the NEW list & index list.*/
2019-09-12 10:33:56 -07:00
do j=1 for words($); y= word($, j) /*process the words (items) in the list*/
if @.y=='' then z= z y; @.y= . /*Not duplicated? Add to Z list,@ array*/
2017-09-23 10:01:46 +02:00
end /*j*/
say
2019-09-12 10:33:56 -07:00
say 'modified list:' space(z) /*stick a fork in it, we're all done. */
2017-09-23 10:01:46 +02:00
say right( words(z), 17, '') 'words in the modified list.'