Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
ralgith
Sorcerer


Joined: 13 Jan 2006
Posts: 715

PostPosted: Tue Dec 11, 2007 5:08 am   

Numerical Sorting...
 
Ok...

Say you have this variable:
Code:
#VAR Blah {10000000|500000|10000|250|5000|250000|1000000|5000000|10|50|1000|50000|1|2000|500|4000000|4000|2000000|100|7500000}


And you want to sort it to be properly listed in numerical significance... does zMUD have a way to do this natively, and DON'T say the %sort, since that returns this:
Code:
1 10 100 1000 10000 1000000 10000000 2000 2000000 250 250000 4000 4000000 50 500 5000 50000 500000 5000000 7500000


Now I know I could do it with a simple little bit of code...
Code:
#while (%numitems(@Blah)) {
  #var temp %item(@Blah,1)
  #loop %numitems(@Blah) {
    #IF (%int(%item(@Blah,%i)) < %int(@temp)) {#var temp %item(@Blah,%i)}
    }
  #ADDITEM Display @temp
  #DELITEM Blah @temp
  }

But Shouldn't zMUD have such a command?

Anyways, As far as I know zMUD does NOT have such a command, so this is mostly a contrived example to show others how it could be done. I'm posting in the CMUD Beta forum to suggest such a command.

[edit]
Forgot to add the %int() around the vars in the if statement, it always comes up false without them...
[/edit]
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Dec 11, 2007 10:03 am   
 
zMUD is feature complete now and won't be developed further. CMUD could potentially include this, though.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Theragil
Apprentice


Joined: 13 Feb 2004
Posts: 157
Location: USA

PostPosted: Tue Dec 11, 2007 4:37 pm   
 
You could always pad the numbers to a fixed length when building the list.
Code:
Blech = ""
#forall @Blah {#additem Blech %rightback( %concat( "         ", %i), 9)}
#show %sort(@Blech)

Ideally you'd be doing the padding when you built the list though, so it wouldn't be as artificial and wasteful as this example.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Dec 11, 2007 4:40 pm   
 
Good idea, though I'd use zeros rather than spaces, and check that the string is a number first.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Theragil
Apprentice


Joined: 13 Feb 2004
Posts: 157
Location: USA

PostPosted: Tue Dec 11, 2007 4:41 pm   
 
Zeroes would be useful in some situations but spaces are easier to trim back off later and look neater to the human eye. The sort doesn't care; space comes before all digits (and indeed everything else printable) in ASCII.
Reply with quote
ralgith
Sorcerer


Joined: 13 Jan 2006
Posts: 715

PostPosted: Tue Dec 11, 2007 9:21 pm   
 
Its quicker and more efficient for me to just run it through my own sorter, and yes I know zMUD is *complete* hence saying it was for others' reference only and that I was suggesting it for CMUD *whaps you all*
_________________
CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Wed Dec 12, 2007 5:09 am   Re: Numerical Sorting...
 
ralgith wrote:
But Shouldn't zMUD have such a command?

I took this to mean "But shouldn't this command be added to zMUD?". Apologies if that isn't what you meant.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
ralgith
Sorcerer


Joined: 13 Jan 2006
Posts: 715

PostPosted: Wed Dec 12, 2007 5:35 am   
 
Nah mate, no apologies are necessary... it was a rhetorical question :)
_________________
CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Tue Jan 29, 2008 3:09 am   
 
This is I think a faster way to sort numerically.
Ascending
#var sortedlist %replace(%mss(%concat("[",%expandlist(@slist,","),"]",".sort(function(A,B){return (Number(A)<Number(B))? -1:(Number(A)==Number(B))?0:1})"),"JScript"),",","|")

Descending
#var sortedlist %replace(%mss(%concat("[",%expandlist(@slist,","),"]",".sort(function(A,B){return (Number(A)>Number(B))? -1:(Number(A)==Number(B))?0:1})"),"JScript"),",","|")
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net