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

#1 2009-06-11 13:07:17

alkaidaserg
Scratcher
Registered: 2009-06-11
Posts: 4

Algorithm

hei got a question:
I need an Algorithm. I hab 5 numbers in my list: 1 3 5 7 9. What should i do that these numbers will go backwards? (9 7 5 3 1)

Offline

 

#2 2009-06-11 13:24:37

bhz
Scratcher
Registered: 2008-07-06
Posts: 100+

Re: Algorithm

Q is just a variable.
list is your original list
listB will be the output list (the original list reversed)

Offline

 

#3 2009-06-11 13:38:03

alkaidaserg
Scratcher
Registered: 2009-06-11
Posts: 4

Re: Algorithm

So I have to create 2 lists?
One list with 13579, the other with 97531 ?
Is there any possibility to do that with only 1 list?

Offline

 

#4 2009-06-11 13:50:09

SmartIrishKid
Scratcher
Registered: 2008-07-19
Posts: 1000+

Re: Algorithm

Make a variable called ReplaceNum and do a script like this:

Code:

set (ReplaceNum) to (item 1 of list)
set (item 1 of list) to (item 5 of list)
set (item 5 of list) to (ReplaceNum)
set (ReplaceNum) to (item 2 of list)
set (item 2 of list) to (item 4 of list)
set (item 4 of list) to (ReplaceNum)

Discuss future Scratch RPGs, online games, and more!

Offline

 

#5 2009-06-11 14:09:15

alkaidaserg
Scratcher
Registered: 2009-06-11
Posts: 4

Re: Algorithm

Im from germany(sorry), what means replacenum?
I mean i dont have "set" for my list. theres only insert replace item add delete.

Last edited by alkaidaserg (2009-06-11 14:13:42)

Offline

 

#6 2009-06-11 14:56:14

cds56
Scratcher
Registered: 2008-05-02
Posts: 500+

Re: Algorithm

set = replace


http://img192.imageshack.us/img192/909/meowdevlogo.pnghttp://i32.tinypic.com/pucti.png

Offline

 

#7 2009-06-11 15:04:01

filo5
Scratcher
Registered: 2008-01-08
Posts: 1000+

Re: Algorithm

ReplaceNum = replacement number.
I propose the two lists and two variables method. Your original list is list, your output list is list2. You'd have to create 1 variable - iter, or i (used for making repeat until loop a for loop)

Code:

set iter to [1]
repeat until <[item (last) from (list2)] = [item (1) from (list)]>
   replace item (iter) of (list2) with (item (length of (list) - (iter))
   change (iter) by (1)

I hope it's readable.


Converting my Scratch projects to Python!

Offline

 

#8 2009-06-11 15:45:09

alkaidaserg
Scratcher
Registered: 2009-06-11
Posts: 4

Re: Algorithm

Thx all!
i finally understood^^ . Now i can do it even with 2 alternatives: First is that I create a new list. I also need a variable. i set variable to 11 and then I change my variable with -2. And this i repeat 5 times so(11-2=9 9-2=5 ...)
Second is SmartIrishKid alternative.

Offline

 

#9 2009-06-12 02:33:57

filo5
Scratcher
Registered: 2008-01-08
Posts: 1000+

Re: Algorithm

I hope we have helped you, and that's what the Forums do.


Converting my Scratch projects to Python!

Offline

 

#10 2009-06-12 07:31:17

bhz
Scratcher
Registered: 2008-07-06
Posts: 100+

Re: Algorithm

alkaidaserg wrote:

So I have to create 2 lists?
One list with 13579, the other with 97531 ?
Is there any possibility to do that with only 1 list?

whoops...i meant to attach an image with scripts! i forgot
here it is...i changed the name of the variable to var
http://img364.imageshack.us/img364/4606/helpy.gif
these scripts basically do the following:
your original list is ListA
add the reverse of ListA to ListB
copy ListB back to ListA

Last edited by bhz (2009-06-12 07:32:31)

Offline

 

#11 2009-06-12 20:13:40

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Algorithm

Basically, transfer the list items into a second list with a variable.

Offline

 

Board footer