This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-04-10 15:15:46

abc123z
New Scratcher
Registered: 2013-04-10
Posts: 3

How do I delete replicate from a list?

Lets say the list has 20 numbers and it has the same number more than once, how do I add it to the replicate list and delete those numbers from the original list?

Offline

 

#2 2013-04-10 15:40:25

abc123z
New Scratcher
Registered: 2013-04-10
Posts: 3

Re: How do I delete replicate from a list?

any help??

Offline

 

#3 2013-04-10 15:40:58

topazdragonlord
Scratcher
Registered: 2013-02-22
Posts: 500+

Re: How do I delete replicate from a list?

Use the

delete (1 v) of [list v]
block  smile

Last edited by topazdragonlord (2013-04-10 15:41:07)


http://i45.tinypic.com/idumbk.png

Offline

 

#4 2013-04-10 15:46:02

abc123z
New Scratcher
Registered: 2013-04-10
Posts: 3

Re: How do I delete replicate from a list?

well I know that, how do you compare the numbers on in the list

Offline

 

#5 2013-04-10 16:06:45

topazdragonlord
Scratcher
Registered: 2013-02-22
Posts: 500+

Re: How do I delete replicate from a list?

perhaps you could try....

delete (1 v) of [list v]//just change the 1 to a customised number
add [number] to [Replica List v]
and then if you mean compare them maybe you could use:
say (List) for (4) secs
say (Replica List) for (4) secs
Is that what you meant?

Last edited by topazdragonlord (2013-04-10 16:07:52)


http://i45.tinypic.com/idumbk.png

Offline

 

#6 2013-04-10 16:36:30

Hyperbola
Scratcher
Registered: 2013-03-15
Posts: 100+

Re: How do I delete replicate from a list?

No... .

Try this:

set [a v] to [1]
delete (all v) of [templist v]
repeat (20)
if <not <[templist v] contains (item (a) of [yourlist v])>>
add (item (a) of [yourlist v]) to [templist v]
end
change [a v] by (1)
end
Using yourlist as the place the numbers are, the output will be in templist and contain no duplicates.

Tested.


Tip of the whatever: Don't post in threads older than 2 weeks unless your post will actually be useful.
It's the last day of 1.4! *cries* (quote from NeilWest, rest by me) by the time you read this it probably will be 2.0  sad

Offline

 

#7 2013-04-10 16:43:30

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: How do I delete replicate from a list?

Hmm... well there's a couple way you could do this. You could scan the list for each number checking for duplicate instances. For example,

set (i) to [0]
repeat until <not <(i) < (length of [list])>>
    set (temp) to item (i) of list
    set (i2) to 0
    repeat until <not <(i2) < (length of [list])>>
        if <(item (i2) of [list]) = (temp)>
            delete item (i2) of [list]
       end
    end
end
Of course, that's horribly inefficient. If your list is sorted you could make one that's more efficient by searching only the indexes adjacent to each item.

Edit: Ugh, formatting. Sorry. I need to go but I'll try and fix that when I get back.

Last edited by Harakou (2013-04-10 23:55:23)


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

Board footer