| View previous topic :: View next topic |
| Author |
Message |
FrEaK_nIcK
Joined: 02 Oct 2007 Posts: 4
|
Posted: Sat Oct 06, 2007 12:06 am Post subject: Sorting |
|
|
Is there a way to sort a number from lowest to highest. Example: 312 gets sorted to 123. Say the code looks like:
| Code: | num_1 = 3
num_2 = 2
num_3 = 1
line = %num_1%%num_2%%num_3% |
This would print out 321, but I want to sort from lowest to highest as in 123. This doesn't work:
| Code: | num_1 = 3
num_2 = 2
num_3 = 1
line = %num_1%%num_2%%num_3%
Sort, line |
just for fyi. Anyone got a good way to make this happen? Thanks in advance. |
|
| Back to top |
|
 |
Serenity
Joined: 08 Nov 2004 Posts: 978
|
Posted: Sat Oct 06, 2007 12:10 am Post subject: |
|
|
Use the R option for Sort.
| Quote: | | R: Sorts in reverse order (alphabetically or numerically depending on the other options). |
Also, the you need to use a delimiter, eg:
line = %num_1%`n%num_2%`n%num_3% |
|
| Back to top |
|
 |
FrEaK_nIcK
Joined: 02 Oct 2007 Posts: 4
|
Posted: Sat Oct 06, 2007 1:02 am Post subject: |
|
|
I don't want a delimiter, I need the numbers to be grouped together. And R doesn't work. Maybe I didn't explain myself clearly.
Lets say I have 6 numbers:
each number has a unique call (variable) so it would look like:
num_1 num_2 num_3
num_4 num_5 num_6
and lets say I make six 3 digit numbers:
132, 321, 213, 123, 231, and 312
each number has it's own variable so it would look like this:
| Code: | line1a = %num_1%%num_2%%num_3% //132
line1b = %num_4%%num_5%%num_6% //321
line1c = %num_3%%num_6%%num_4% //213
line1d = %num_1%%num_3%%num_2% //123
line1e = %num_5%%num_4%%num_6% //231
line1f = %num_4%%num_6%%num_5% //312 |
Now what I want to do is sort all possible combinations of the number from lowest to highest which in this example is 123. I hope that helps a bit in the explanation.  |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Sat Oct 06, 2007 1:20 am Post subject: |
|
|
The R option would give 321
the delimiter is what you need. _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
FrEaK_nIcK
Joined: 02 Oct 2007 Posts: 4
|
Posted: Sat Oct 06, 2007 4:11 am Post subject: |
|
|
| engunneer wrote: | The R option would give 321
the delimiter is what you need. |
The R option would have the number going down to 0 which is the opposite of what I want. I need the number to increase from 0. Also the delimiter cause the numbers to break, something I also don't want.
I appreciate the help but I think I'll use C# or PHP to develop this project. I was just testing AHK because a friend pointing me in this direction. |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Sat Oct 06, 2007 5:31 am Post subject: |
|
|
I somehow missed your previous post.
| Code: |
line1 = %num_1%%num_2%%num_3% //132
line2 = %num_4%%num_5%%num_6% //321
line3 = %num_3%%num_6%%num_4% //213
line4 = %num_1%%num_3%%num_2% //123
line5 = %num_5%%num_4%%num_6% //231
line6 = %num_4%%num_6%%num_5% //312
Loop, 6
lines .= line%A_index% . "`n"
StringTrimRight, lines, lines, 1
Sort, lines
Msgbox, %lines%
;if you want them split back out
StringSplit, line, lines, `n, `r
listvars
pause
|
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
FrEaK_nIcK
Joined: 02 Oct 2007 Posts: 4
|
Posted: Sat Oct 06, 2007 11:51 am Post subject: |
|
|
@engunneer
I was a good idea but it doesn't work either. All it does is sort not number from smallest to largest but doesn't sort the number itself. Thanks though, but I'll program it through C#, I can accomplish what I need there with Array.Sort or something.  |
|
| Back to top |
|
 |
|