Jump to content

Consecutive Number Counter


Recommended Posts

Heya Peeps,

I'm attempting to make a number counter (1, 2, 3, etc...), that part is no problem. As a challenge, when the number gets into multiple digits, I want to use a combination of numbers to form the new number. Say I have 0 - 9 in a array, when the counter gets to 10, I want it to use 1 and 0 to form 10.

I realize that there are better ways to do this, and the numbers in the array is stupid, but I'm bored and am just doing this as a proof of concept and to grasp the concept of arrays in loops. Anyways... I know how to get it started, the part I'm having trouble with is how to add multiple parts of the array together to form one number and how to make it automatically add another number each time it each time it exhausts all possible options for that loop.

Dim $Number[15], $CurrentDigits

$MaxDigits = 2;Maximum number of digits

$Number[0] = 10;Number of elements in $Number
$Number[1] = 0
$Number[2] = 1
$Number[3] = 2
$Number[4] = 3
$Number[5] = 4
$Number[6] = 5
$Number[7] = 6
$Number[8] = 7
$Number[9] = 8
$Number[10] = 9

For $loop = 1 To $Number[0]
    $CurrentNumber = $Number[$loop]
    MsgBox(0, "Counter", $CurrentNumber)
    If $CurrentNumber = $Number[$Number[0]] & $CurrentDigits <> $MaxDigits Then
        
    EndIf
    If $CurrentNumber = $Number[$Number[0]] & $CurrentDigits = $MaxDigits Then
        MsgBox(0, "Counter", "End")
    EndIf
Next

That's what I have so far... Any suggestions?

Thanks,

Jaysen

Edited by Jaysen
Link to comment
Share on other sites

From what I can see he wants the loop to count to 99 using the elements from 0 to 9 in his array using a loop of 10.

The $MaxDigits = 2;Maximum number of digits is what makes me think this.

But $MaxDigits would actually need a stringlen() check to work as check to how many digits there are in the $CurrentDigits.

I was having a look and trying to stick with his confines..

But as he's said there's better ways to play counting games with arrays.

Cheers

Link to comment
Share on other sites

Heya,

I know how to make it just count without stopping. I am trying to get it to combine numbers to form one number. For example... 2 and 3 to make 23, 4 and 2 to make 42.

Thanks,

Jaysen

I don't understand...

i don't know what you want...

You mean you just want to do something like:

Dim $a[3]
$a[1] =0
$a[2] =1

MsgBox(0,"", $a[2] & $a[1]);gives 1 & 0 which makes 10
Link to comment
Share on other sites

OIC

You are getting into nested for loops if i am not mistaken.

I don't know how you would do it with a definable number of max digits.

That may have to be hardcoded

Dim $Number[15], $CurrentDigits

$MaxDigits = 2;Maximum number of digits

$Number[0] = 10;Number of elements in $Number   
For $a = 1 to $Number[0]
    $Number[$a] = $a-1
Next

For $loop1 = 1 to $Number[0]
    For $loop2 = 1 to $Number[0]
        MsgBox(0,"", $Number[$Loop1]&$Number[$Loop2])
    Next
Next

You would have to do a whole new for loop, and a new variable in the msgbox for each digit.

Edited by Paulie
Link to comment
Share on other sites

Heya,

Lemme see if I could clear this up...

I want the script to count until I stop it, or when the length of the result equals $MaxDigits AND all options have been exhausted. For example, If $MaxDigits = 3 Then it would count into the hundreds and would stop before it went into the thousands. Meaning If $CurrentNumber = 567 it is 3 digits long, but it would still keep going because it hasn't tried all possible values until $CurrentNumber = 999. $After 999, it gets into 1000 which is 4 digits long, so it would stop at 999.

As for the seperate numbers... I don't want 1 variable to increment until it reaches the end result, that's too easy. I want any variable to go higher than a 9. So 10 would be something like MsgBox(0, "Counter", $Number[2] + "" + $Number[1]). The quotes in the middle is so it doesn't add those numbers together, it shows them each seperately.

Thanks,

Jaysen

Link to comment
Share on other sites

Heya,

Yes, that's the general idea of what I'm aiming for. I know it has to be a nested loop, but I haven't had much experience with them, that's why I'm trying to do this so that I can better understand them. I don't quite understand how to reassign $CurrentNumber to add a extra number each time the value increments to another place (ones, tens, hundreds, etc...)

Thanks,

Jaysen

Link to comment
Share on other sites

Heya,

Yes, that's the general idea of what I'm aiming for. I know it has to be a nested loop, but I haven't had much experience with them, that's why I'm trying to do this so that I can better understand them. I don't quite understand how to reassign $CurrentNumber to add a extra number each time the value increments to another place (ones, tens, hundreds, etc...)

Thanks,

Jaysen

You are in pretty deep... i will look into it, but im hitting alot of dead ends testing. :rolleyes:
Link to comment
Share on other sites

Heya,

Thanks. I do alot of coding with other languages such as VB, C++, Java to name a few, but I never really got into nested loops. This is one of the easiest languages I've found to pickup on, and I figured I'd be able to do it without too much of a problem, but I'm still stuck...

I really appreciate it! I'm still working on it too, let me know if you come across anything ok?

Thanks,

Jaysen

Link to comment
Share on other sites

Maybe you should look into a recursive function. Here is a factorial example. The only problem is that to write an accumulator you would have to pass a depth (maxdigits) paramater and the last position of your for loop, and somehow return both.

Link to comment
Share on other sites

Heya,

Thanks for the suggestion, it's been awhile since anyone has replied. I was starting to think that this was dead. This is a small part of a larger program I'm working on and the sooner it's done, the better. There's got to be a easy way to do this... I'm sure there's some other programs out there that deal with the same situation. I appreciate the suggestion, I'll look into it.

Thnx

Jaysen

Link to comment
Share on other sites

I only scanned this thread so I may have missed the exact form that you want the numbers in. I understand that you want one digit per variable, I'm just unclear as to how you plan on using them - so it is difficult to suggest a why to generate/store them.

Anyway, i would try and generate them using the code in this post:

http://www.autoitscript.com/forum/index.ph...ost&p=74476

[change $STR="A,B,C,D,E,F,G" to $STR="0,1,2,3,4,5,6,7,8,9"]

Further down in that thread you will see a version that outputs to an array. The next step for your usage would be to cycle thru the array performing a StringSplit on each element - splitting each into single characters.

Was I as clear as mud?

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

I have yet to find a recursive way to do this, but if you can find some way to convert this nested method you should be fine.

This will comma separate all the numbers into a string and print the entire thing at once.

#include <Array.au3>
$theArray = _ArrayCreate (0,1,2,3,4,5,6,7,8JBÔ[]H[XÛHNNNB[H   ÌÍÓSHH   ][ÝÉ][ÝÂÜ  ÌÍâb33c·FT'& f÷"b33c´"âb33c·FT'&"b33c´2âb33c·FÉÉä($$$ÀÌØí9U4µÀìôÀÌØíÑ¡ÉÉålÀÌØítµÀìÀÌØíÑ¡ÉÉålÀ6;B] & $theArray[$C] & ","
        Next
    Next
Next

MÙÐÞ
    ][ÝÉ][ÝË    ÌÍÓSJBÔ[]H[XÛHNNNNB[H  ÌÍ´åTÒÒgV÷C²gV÷C° ¤f÷"b33c´âb33c·FT'& f÷"b33c´"âb33c·FÉÉä($%½ÈÀÌØí¥¸ÀÌØíÑ¡ÉÉä($$%½ÈÀÌØí¥¸ÀÌØíÑ¡ÉÉä($$$$#036;NUM &= $theArray[$A] & $theArray[$B] &  ÌÍÝP^VÉÌÍÐ×H    [È ÌÍÝP^VÉÌÍÑH  [È ][ÝË  ][ÝÂæW@ æW@ æW@¤æW@ ¤×6t&÷ÂgV÷C²gV÷C²Âb33c´åTÒ
Link to comment
Share on other sites

Heya,

Thanks alot for the replies! Thanks to the link herewasplato gave, I found what I needed. I didn't exactly want it to write it to a txt file, but I can work with it to do what I need. Consider this thread closed.

Thnx

Jaysen

Link to comment
Share on other sites

  • 3 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...