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

#1 2011-09-24 16:49:55

Thenuclearduck
Scratcher
Registered: 2010-10-17
Posts: 100+

Sorting lists?

Here's my problem: I have a list where I want it to automatically sort a group of data in ascending order, so that the biggest amount is at the bottom.
This is what one piece of data looks like:

[ABC        1:34]
I want the time to be sorted, but not the name (ABC) so that the fastest time is first. Does anyone know how to order lists in this way? Thanks for any help you can give me.  smile

Last edited by Thenuclearduck (2011-09-24 16:50:12)


http://blocks.scratchr.org/API.php?user=Thenuclearduck&action=projects&type=newest&return=text&num=1 is my newest project! It has http://blocks.scratchr.org/API.php?user=Thenuclearduck&action=projects&type=newest&return=views&num=1 views!

Offline

 

#2 2011-09-24 16:53:36

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Sorting lists?

Thenuclearduck wrote:

Here's my problem: I have a list where I want it to automatically sort a group of data in ascending order, so that the biggest amount is at the bottom.
This is what one piece of data looks like:

[ABC        1:34]
I want the time to be sorted, but not the name (ABC) so that the fastest time is first. Does anyone know how to order lists in this way? Thanks for any help you can give me.  smile

It would be easiest to store the names and times in seperate lists, so you don't have to parse it.  It would be also easier to just list it in seconds (i.e. 1:34 = 94) and convert it later.

Offline

 

#3 2011-09-24 17:03:08

Thenuclearduck
Scratcher
Registered: 2010-10-17
Posts: 100+

Re: Sorting lists?

Greenatic wrote:

Thenuclearduck wrote:

Here's my problem: I have a list where I want it to automatically sort a group of data in ascending order, so that the biggest amount is at the bottom.
This is what one piece of data looks like:

[ABC        1:34]
I want the time to be sorted, but not the name (ABC) so that the fastest time is first. Does anyone know how to order lists in this way? Thanks for any help you can give me.  smile

It would be easiest to store the names and times in seperate lists, so you don't have to parse it.  It would be also easier to just list it in seconds (i.e. 1:34 = 94) and convert it later.

I understand, but is there any way to order it in the form it is in now?


http://blocks.scratchr.org/API.php?user=Thenuclearduck&action=projects&type=newest&return=text&num=1 is my newest project! It has http://blocks.scratchr.org/API.php?user=Thenuclearduck&action=projects&type=newest&return=views&num=1 views!

Offline

 

#4 2011-09-24 17:18:20

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Sorting lists?

Thenuclearduck wrote:

Greenatic wrote:

Thenuclearduck wrote:

Here's my problem: I have a list where I want it to automatically sort a group of data in ascending order, so that the biggest amount is at the bottom.
This is what one piece of data looks like:

[ABC        1:34]
I want the time to be sorted, but not the name (ABC) so that the fastest time is first. Does anyone know how to order lists in this way? Thanks for any help you can give me.  smile

It would be easiest to store the names and times in seperate lists, so you don't have to parse it.  It would be also easier to just list it in seconds (i.e. 1:34 = 94) and convert it later.

I understand, but is there any way to order it in the form it is in now?

Well, yes.  But it will be painfully difficult, because you have to parse it.

Offline

 

#5 2011-09-24 17:28:31

Thenuclearduck
Scratcher
Registered: 2010-10-17
Posts: 100+

Re: Sorting lists?

Greenatic wrote:

Thenuclearduck wrote:

Greenatic wrote:


It would be easiest to store the names and times in seperate lists, so you don't have to parse it.  It would be also easier to just list it in seconds (i.e. 1:34 = 94) and convert it later.

I understand, but is there any way to order it in the form it is in now?

Well, yes.  But it will be painfully difficult, because you have to parse it.

Could you tell me how? (If you know.) If you don't know just tell me how to do it with all the stuff you sggested.


http://blocks.scratchr.org/API.php?user=Thenuclearduck&action=projects&type=newest&return=text&num=1 is my newest project! It has http://blocks.scratchr.org/API.php?user=Thenuclearduck&action=projects&type=newest&return=views&num=1 views!

Offline

 

#6 2011-09-24 18:03:56

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Sorting lists?

Thenuclearduck wrote:

Greenatic wrote:

Thenuclearduck wrote:

I understand, but is there any way to order it in the form it is in now?

Well, yes.  But it will be painfully difficult, because you have to parse it.

Could you tell me how? (If you know.) If you don't know just tell me how to do it with all the stuff you sggested.

Well, I'm not sure about the parser.  So to convert your M:S times to S, just use (M * 60) + S.  (And, just so you know, I meant to put two identical repeat loops in this code).

set counter to 1.
repeat (length of times) {
  repeat (length of times) {
    if <not <(counter) = (length of times)>> {
      if <(item (counter) of times) > (item ((counter) + 1) of times)> {
        set sorter to (item (counter) of times).
        replace item (counter) of times with (item ((counter) + 1) of times).
        replace item ((counter) + 1) of times with (sorter). 
      }
    }
    change sorter by 1.
  }
set counter to 1.
}

Last edited by Greenatic (2011-09-24 18:04:02)

Offline

 

#7 2011-09-24 18:11:08

Thenuclearduck
Scratcher
Registered: 2010-10-17
Posts: 100+

Re: Sorting lists?

Greenatic wrote:

Thenuclearduck wrote:

Greenatic wrote:


Well, yes.  But it will be painfully difficult, because you have to parse it.

Could you tell me how? (If you know.) If you don't know just tell me how to do it with all the stuff you sggested.

Well, I'm not sure about the parser.  So to convert your M:S times to S, just use (M * 60) + S.  (And, just so you know, I meant to put two identical repeat loops in this code).

set counter to 1.
repeat (length of times) {
  repeat (length of times) {
    if <not <(counter) = (length of times)>> {
      if <(item (counter) of times) > (item ((counter) + 1) of times)> {
        set sorter to (item (counter) of times).
        replace item (counter) of times with (item ((counter) + 1) of times).
        replace item ((counter) + 1) of times with (sorter). 
      }
    }
    change sorter by 1.
  }
set counter to 1.
}

In that case, how can I get the name to stay with the number when the numbers are sorted?


http://blocks.scratchr.org/API.php?user=Thenuclearduck&amp;action=projects&amp;type=newest&amp;return=text&amp;num=1 is my newest project! It has http://blocks.scratchr.org/API.php?user=Thenuclearduck&amp;action=projects&amp;type=newest&amp;return=views&amp;num=1 views!

Offline

 

#8 2011-09-24 21:12:19

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Sorting lists?

Thenuclearduck wrote:

Greenatic wrote:

Thenuclearduck wrote:

Could you tell me how? (If you know.) If you don't know just tell me how to do it with all the stuff you sggested.

Well, I'm not sure about the parser.  So to convert your M:S times to S, just use (M * 60) + S.  (And, just so you know, I meant to put two identical repeat loops in this code).

set counter to 1.
repeat (length of times) {
  repeat (length of times) {
    if <not <(counter) = (length of times)>> {
      if <(item (counter) of times) > (item ((counter) + 1) of times)> {
        set sorter to (item (counter) of times).
        replace item (counter) of times with (item ((counter) + 1) of times).
        replace item ((counter) + 1) of times with (sorter). 
      }
    }
    change sorter by 1.
  }
set counter to 1.
}

In that case, how can I get the name to stay with the number when the numbers are sorted?

Sorry it took me so long to reply. 

Create another variable, "nsorter".  Replace the previous code with this:


set counter to 1.
repeat (length of times) {
  repeat (length of times) {
    if <not <(counter) = (length of times)>> {
      if <(item (counter) of times) > (item ((counter) + 1) of times)> {
        set sorter to (item (counter) of times).
        set nsorter to (item (counter) of names).
        replace item (counter) of times with (item ((counter) + 1) of times).
        replace item ((counter) + 1) of times with (sorter). 
        replace item (counter) of names with (item ((counter) + 1) of names).
        replace item ((counter) + 1) of names with (nsorter). 
      }
    }
    change sorter by 1.
  }
set counter to 1.
}

Last edited by Greenatic (2011-09-24 21:12:27)

Offline

 

#9 2011-09-25 03:50:51

Thenuclearduck
Scratcher
Registered: 2010-10-17
Posts: 100+

Re: Sorting lists?

Thank you very much this works perfectly now I can have a leaderboard. I will give you plenty of credit in the project notes!


http://blocks.scratchr.org/API.php?user=Thenuclearduck&amp;action=projects&amp;type=newest&amp;return=text&amp;num=1 is my newest project! It has http://blocks.scratchr.org/API.php?user=Thenuclearduck&amp;action=projects&amp;type=newest&amp;return=views&amp;num=1 views!

Offline

 

#10 2011-09-25 06:07:29

Thenuclearduck
Scratcher
Registered: 2010-10-17
Posts: 100+

Re: Sorting lists?

I've just noticed how the sorter only seems to be ble to sort 3 entries. Do you know why?


http://blocks.scratchr.org/API.php?user=Thenuclearduck&amp;action=projects&amp;type=newest&amp;return=text&amp;num=1 is my newest project! It has http://blocks.scratchr.org/API.php?user=Thenuclearduck&amp;action=projects&amp;type=newest&amp;return=views&amp;num=1 views!

Offline

 

#11 2011-09-25 13:06:53

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Sorting lists?

Thenuclearduck wrote:

I've just noticed how the sorter only seems to be ble to sort 3 entries. Do you know why?

Is "times" only 3 entries long?  Let me test it for a second, maybe I typed something wrong...

EDIT:  Yeah, I typed some things wrong.  New code:

set counter to 1.
repeat (length of times) {
  repeat (length of times) {
    if <not <(counter) = 1>> {
      if <(item (counter) of times) < (item ((counter) - 1) of times)> {
        set sorter to (item (counter) of times).
        set nsorter to (item (counter) of names).
        replace item (counter) of times with (item ((counter) - 1) of times).
        replace item ((counter) - 1) of times with (sorter).
        replace item (counter) of names with (item ((counter) - 1) of names).
        replace item ((counter) - 1) of names with (nsorter).
        }
      }
    change counter by 1.
    }
  set counter to 1.
  }

Sorry for the error last time.  This should work.

Last edited by Greenatic (2011-09-25 13:18:47)

Offline

 

#12 2011-09-25 14:59:51

Thenuclearduck
Scratcher
Registered: 2010-10-17
Posts: 100+

Re: Sorting lists?

Ok, thanks I will try this.


http://blocks.scratchr.org/API.php?user=Thenuclearduck&amp;action=projects&amp;type=newest&amp;return=text&amp;num=1 is my newest project! It has http://blocks.scratchr.org/API.php?user=Thenuclearduck&amp;action=projects&amp;type=newest&amp;return=views&amp;num=1 views!

Offline

 

#13 2011-11-04 18:17:35

Thenuclearduck
Scratcher
Registered: 2010-10-17
Posts: 100+

Re: Sorting lists?

Hey, the game I was gonna do with this is now done, so here it is. http://scratch.mit.edu/projects/Thenuclearduck/2046581


http://blocks.scratchr.org/API.php?user=Thenuclearduck&amp;action=projects&amp;type=newest&amp;return=text&amp;num=1 is my newest project! It has http://blocks.scratchr.org/API.php?user=Thenuclearduck&amp;action=projects&amp;type=newest&amp;return=views&amp;num=1 views!

Offline

 

#14 2011-11-04 20:43:28

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Sorting lists?

Just so you know, this should probably have been in All About Scratch, not Advanced Topics.  It is a common misconception that Advanced Topics are for more advanced code for Scratch projects, but it is actually for programming that goes beyond Scratch (e.g. Squeak, HTML, C++, etc.)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#15 2011-11-04 20:52:53

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: Sorting lists?

MoreGamesNow wrote:

Just so you know, this should probably have been in All About Scratch, not Advanced Topics.  It is a common misconception that Advanced Topics are for more advanced code for Scratch projects, but it is actually for programming that goes beyond Scratch (e.g. Squeak, HTML, C++, etc.)

Welcome to the Advanced Topics wrote:

• Advanced Scratch Programming
Yes, the ATs are also a place to share advanced Scratch programming. Scratch programs that use complex algorithms, or are breakthroughs in Scratch (ie a recursive engine, a chess engine, or a programming language within Scratch), deserve to be shared and discussed here. Sometimes, people integrate Scratch with other languages (The coolest example I can think of would be connecting it to AppleScript, to read the Gyroscopic sensor values of a MacBook Pro, for a balance game), connect it to the real world in cool ways (People have used Bluetooth to use a Wii remote or Kinect to control Scratch), or connect Scratch programs via Mesh (I've seen many chat programs). The idea is not to advertise, but to develop.
SEE HERE

**cough*ignorance*cough*

Last edited by Greatdane (2011-11-04 20:53:42)


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

#16 2011-11-04 22:39:31

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Sorting lists?

Scratch Website wrote:

Advanced Topics: "Talk about technical aspects or advanced features."

All About Scratch: "Questions about Scratch? No question is too basic! "

This may simply be my opinion, but it seems to me that any questions about using Scratch to make  projects belongs in "questions about scratch", not "technical aspects or advanced features", as using blocks to make projects are what Scratch is all about and therefore - in my opinion - do not fall under "advanced features".

And your quote above talks about sharing advanced projects, not asking for help with them.

I guess when two people get their information from two different sources, their resulting opinions are bound to differ.

Last edited by MoreGamesNow (2011-11-04 22:44:24)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#17 2011-11-05 05:30:41

Thenuclearduck
Scratcher
Registered: 2010-10-17
Posts: 100+

Re: Sorting lists?

MoreGamesNow wrote:

Scratch Website wrote:

Advanced Topics: "Talk about technical aspects or advanced features."

All About Scratch: "Questions about Scratch? No question is too basic! "

This may simply be my opinion, but it seems to me that any questions about using Scratch to make  projects belongs in "questions about scratch", not "technical aspects or advanced features", as using blocks to make projects are what Scratch is all about and therefore - in my opinion - do not fall under "advanced features".

And your quote above talks about sharing advanced projects, not asking for help with them.

I guess when two people get their information from two different sources, their resulting opinions are bound to differ.

No question is too basic!
Technical aspects or advanced features.

Which one sounds more fitting to a quite advanced question that appears to have never been solved before on the forums?


http://blocks.scratchr.org/API.php?user=Thenuclearduck&amp;action=projects&amp;type=newest&amp;return=text&amp;num=1 is my newest project! It has http://blocks.scratchr.org/API.php?user=Thenuclearduck&amp;action=projects&amp;type=newest&amp;return=views&amp;num=1 views!

Offline

 

#18 2011-11-05 09:18:10

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Sorting lists?

I (writer of the quote above  big_smile ) think this particular question is likely to fit in All About Scratch, because it is normal, though complex code. Advanced projects usually involve hard math or complex techniques, not complex code. You could put together a hundred blocks that just make a sprite move in a special way, or you could create a mathematical equation to cater to that motion. The latter is more advanced as it is "non-conventional" in a way.

It's hard to explain...  tongue


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#19 2011-11-11 03:10:40

Thenuclearduck
Scratcher
Registered: 2010-10-17
Posts: 100+

Re: Sorting lists?

Hardmath123 wrote:

I (writer of the quote above  big_smile ) think this particular question is likely to fit in All About Scratch, because it is normal, though complex code. Advanced projects usually involve hard math or complex techniques, not complex code. You could put together a hundred blocks that just make a sprite move in a special way, or you could create a mathematical equation to cater to that motion. The latter is more advanced as it is "non-conventional" in a way.

It's hard to explain...  tongue

*shrugs* I don't really get all the fuss about moving forums. Unless you put sommething that has absolutely nothing to do with a forum in it, you get the question answered, don't you? Why does it matter which of two similar forums is it in?


http://blocks.scratchr.org/API.php?user=Thenuclearduck&amp;action=projects&amp;type=newest&amp;return=text&amp;num=1 is my newest project! It has http://blocks.scratchr.org/API.php?user=Thenuclearduck&amp;action=projects&amp;type=newest&amp;return=views&amp;num=1 views!

Offline

 

Board footer