# Help With Logic Of Permutations

## Recommended Posts

I have 6 variables and 6 positions available for those variables. A variable can be true or false. If a variable is true, it will take a position. If a variable is not true, it will not take a position.

The ratio of true variables to positions will always be equal (1:1). In other words, a position will only be created if it is needed. So if 3 variables are true, 3 positions are created. If 6 variables are true, then 6 positions are created.

Each variable is ranked by importance in the 6 possible positions. Each variable will always maintain its rank in relation to other variables. For instance, let us say the 6 variables are \$A, \$B, \$C, \$D, \$E, \$F. If all 6 variables are true, they will take the positions {1,2,3,4,5,6}; so {\$A, \$B, \$C, \$D, \$E, \$F}.

If any variable is not true, then while maintaining rank they will receive a 'higher' rank. For instance, if \$C is not true, while all other variables are true, then {\$A,\$B,\$D,\$E,\$F}.

****EDIT**** Another example, if \$A, \$B, \$E are False, and all else is True, then {\$C, \$D,\$F}. But, {\$C, \$F, \$D} or {\$F, \$D, \$C} or {\$F, \$C, \$D} or {\$D, \$C, \$F} or {\$D, \$F, \$C} are False.

How do I create commands/rules to inform the Script of these rules. I have no idea if I should make a bunch of If..Then statements with all the possible permutations, or something else. I would think the If..Then approach would get ugly.

What do you reccomend? By the way, I didn't provide any code of what I am working on, because I thought it would be much easier to explain and answer this way. Thanks in advance.

*******EDIT*******

Feel free to respond in Psuedo Code. This is more about ideas at this point.

Edited by litlmike
##### Share on other sites

• Moderators

I have 6 variables and 6 positions available for those variables. A variable can be true or false. If a variable is true, it will take a position. If a variable is not true, it will not take a position.

The ratio of true variables to positions will always be equal (1:1). In other words, a position will only be created if it is needed. So if 3 variables are true, 3 positions are created. If 6 variables are true, then 6 positions are created.

Each variable is ranked by importance in the 6 possible positions. Each variable will always maintain its rank in relation to other variables. For instance, let us say the 6 variables are \$A, \$B, \$C, \$D, \$E, \$F. If all 6 variables are true, they will take the positions {1,2,3,4,5,6}; so {\$A, \$B, \$C, \$D, \$E, \$F}.

If any variable is not true, then while maintaining rank they will receive a 'higher' rank. For instance, if \$C is not true, while all other variables are true, then {\$A,\$B,\$D,\$E,\$F}.

How do I create commands/rules to inform the Script of these rules. I have no idea if I should make a bunch of If..Then statements with all the possible permutations, or something else. I would think the If..Then approach would get ugly.

What do you reccomend? By the way, I didn't provide any code of what I am working on, because I thought it would be much easier to explain and answer this way. Thanks in advance.

http://www.autoitscript.com/forum/index.ph...ndpost&p=102172

Might give you some ideas...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

Something like this?

```#include <array.au3>
Global \$A = True, \$B = True, \$C = False, \$D = True, \$E = True, \$F = True, \$Pos[1], \$counter = 0

For \$i = 65 To 70; "A" to "F" in ascii
If Eval (Chr (\$i)) = True Then
\$counter += 1
ReDim \$Pos[\$counter + 1]
\$Pos[0] = \$counter
\$Pos[\$counter] = Chr (\$i); or true..  or what..?
EndIf
Next
_ArrayDisplay (\$pos, "posses")```
##### Share on other sites

I have 6 variables and 6 positions available for those variables. A variable can be true or false. If a variable is true, it will take a position. If a variable is not true, it will not take a position.

The ratio of true variables to positions will always be equal (1:1). In other words, a position will only be created if it is needed. So if 3 variables are true, 3 positions are created. If 6 variables are true, then 6 positions are created.

Each variable is ranked by importance in the 6 possible positions. Each variable will always maintain its rank in relation to other variables. For instance, let us say the 6 variables are \$A, \$B, \$C, \$D, \$E, \$F. If all 6 variables are true, they will take the positions {1,2,3,4,5,6}; so {\$A, \$B, \$C, \$D, \$E, \$F}.

If any variable is not true, then while maintaining rank they will receive a 'higher' rank. For instance, if \$C is not true, while all other variables are true, then {\$A,\$B,\$D,\$E,\$F}.

How do I create commands/rules to inform the Script of these rules. I have no idea if I should make a bunch of If..Then statements with all the possible permutations, or something else. I would think the If..Then approach would get ugly.

What do you reccomend? By the way, I didn't provide any code of what I am working on, because I thought it would be much easier to explain and answer this way. Thanks in advance.

I believe rather than using individual variables, I would use an array with a possibility of 7 elements (since the [0] element is the array count)

This way if the variables are true as in your exmple above: ({\$A,\$B,\$D,\$E,\$F})

```Dim \$myArray[7]

\$myArray[1] = \$A
\$myArray[2] = \$B
\$myArray[3] = \$D
\$myArray[4] = \$E
\$myArray[5] = \$F

; example of testing and assigning

Dim \$Count = 1
Select

Case \$A
\$myArray[\$Count] = \$A
\$Count &= 1

Case \$C
\$myArray[\$Count] = \$C
\$Count &= 1

Case \$D
\$myArray[\$Count] = \$D
\$Count &= 1

Case \$E
\$myArray[\$Count] = \$E
\$Count &= 1

Case \$F
\$myArray[\$Count] = \$F

EndSelect

; loop to retrieve the values
For \$i = 1 to UBound(\$myArray)
\$ReturnValue = \$myArray[\$i]
Next```
##### Share on other sites

I believe rather than using individual variables, I would use an array with a possibility of 7 elements (since the [0] element is the array count)

This way if the variables are true as in your exmple above: ({\$A,\$B,\$D,\$E,\$F})

```Dim \$myArray[7]

\$myArray[1] = \$A
\$myArray[2] = \$B
\$myArray[3] = \$D
\$myArray[4] = \$E
\$myArray[5] = \$F

; example of testing and assigning

Dim \$Count = 1
Select

Case \$A
\$myArray[\$Count] = \$A
\$Count &= 1

Case \$C
\$myArray[\$Count] = \$C
\$Count &= 1

Case \$D
\$myArray[\$Count] = \$D
\$Count &= 1

Case \$E
\$myArray[\$Count] = \$E
\$Count &= 1

Case \$F
\$myArray[\$Count] = \$F

EndSelect

; loop to retrieve the values
For \$i = 1 to UBound(\$myArray)
\$ReturnValue = \$myArray[\$i]
Next```
Thanks to everyone that has responded, they all have given me some needed direction. The quote above, I think, may be the most practical for what I want to do. However, I still need to learn more about arrays, like what they are, how to use them, etc. Anyone have any reading material for me?

Also, can anyone help me understand what the following commands do (from above)? [7] (or anything with a number in the bracket), \$myArray[\$Count], UBound(\$myArray), \$ReturnValue = \$myArray[\$i]. Thanks again.

##### Share on other sites

• Moderators

An Array is a list with individual elements.

\$MyArray is the Storage variable for that list of information

[7] is the number of elements in the list

Ubound(\$myArray) get's the total number of elements available in the array

\$myArray[\$i] << \$i in a loop holds the current element number your on.

```Local \$MyArray[7]; << Number of elements + 1 / Must be declared with Local / Dim / Global
\$MyArray[1] = 'One';[1] the element holds the value of 'One'
\$MyArray[2] = 'Two'
\$MyArray[3] = 'Three'
\$MyArray[4] = 'Four'
\$MyArray[5] = 'Five'
\$MyArray[6] = 'Six'

For \$i = 1 To Ubound(\$MyArray) - 1; Since we've declared \$MyArray with 7 elements we only need the 6
MsgBox(0, 'Example', 'Element Number ' & \$i & ' = ' & \$MyArray[\$i])
Next```

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

An Array is a list with individual elements.

\$MyArray is the Storage variable for that list of information

[7] is the number of elements in the list

Ubound(\$myArray) get's the total number of elements available in the array

\$myArray[\$i] << \$i in a loop holds the current element number your on.

```Local \$MyArray[7]; << Number of elements + 1 / Must be declared with Local / Dim / Global
\$MyArray[1] = 'One';[1] the element holds the value of 'One'
\$MyArray[2] = 'Two'
\$MyArray[3] = 'Three'
\$MyArray[4] = 'Four'
\$MyArray[5] = 'Five'
\$MyArray[6] = 'Six'

For \$i = 1 To Ubound(\$MyArray) - 1; Since we've declared \$MyArray with 7 elements we only need the 6
MsgBox(0, 'Example', 'Element Number ' & \$i & ' = ' & \$MyArray[\$i])
Next```

and if your using the beta you can shorten that up even more, 2 examples below

```Local \$MyArray[7] = ['','One','Two','Three','Four','Five','Six']; << Number of elements + 1 / Must be declared with Local / Dim / Global

For \$i = 1 To Ubound(\$MyArray) - 1; Since we've declared \$MyArray with 7 elements we only need the 6
MsgBox(0, 'Example', 'Element Number ' & \$i & ' = ' & \$MyArray[\$i])
Next

Local \$MyArray[6] = ['One','Two','Three','Four','Five','Six']; << Number of elements + 1 / Must be declared with Local / Dim / Global

For \$i = 0 To Ubound(\$MyArray) - 1; Since we've declared \$MyArray with 6 elements we only need the 5
MsgBox(0, 'Example', 'Element Number ' & \$i & ' = ' & \$MyArray[\$i])
Next```

Â

Don't argue with an idiot; people watching may not be able to tell the difference.

Â

##### Share on other sites

An Array is a list with individual elements.

\$MyArray is the Storage variable for that list of information

[7] is the number of elements in the list

Ubound(\$myArray) get's the total number of elements available in the array

\$myArray[\$i] << \$i in a loop holds the current element number your on.

```Local \$MyArray[7]; << Number of elements + 1 / Must be declared with Local / Dim / Global
\$MyArray[1] = 'One';[1] the element holds the value of 'One'
\$MyArray[2] = 'Two'
\$MyArray[3] = 'Three'
\$MyArray[4] = 'Four'
\$MyArray[5] = 'Five'
\$MyArray[6] = 'Six'

For \$i = 1 To Ubound(\$MyArray) - 1; Since we've declared \$MyArray with 7 elements we only need the 6
MsgBox(0, 'Example', 'Element Number ' & \$i & ' = ' & \$MyArray[\$i])
Next```
Good input everyone. Thanks for the above example, it helped me understand the purpose of arrays a bit better. I been doing some reading on them today and it looks like this is the direction I need to take.

I would like to make this a bit more practical than theoretical and see what kind of input everyone can give. From what I can tell, I can make an array that will count how many variables were true, from the User Input-1-6 is possible. Then, with that number, tell the script where/how to place the variables.

The thing that I am stuck on the most, is how do I tell the script the 'rank' of the variable? Even if the script is not 'aware' of the 'rank', then at least the script must at least execute in 'order'. Meaning, how does the script 'know' that \$A is the top ranking variable, and all other variables 'inferior'?

For example, the User gives the script the input \$A = True, \$F = True, all else are False. Then the script must 'rank'/execute functions related to \$A, then \$F. Never the reverse order. Likewise, if \$A = False, \$D = True, \$F = True, then the 'rank' must be \$D, \$F.

Feel free to respond in Psuedo Code. This is more about ideas at this point.

##### Share on other sites

Well since you're putting the values in the array in order, why not just call the array one element at a time?

Example:

\$Array[1] = \$A

\$Array[2] = \$C

\$Array[3] = \$D

\$Array[4] = \$F

Just call \$Array[1], then 2, then 3, then 4.

##### Share on other sites

maybe

```Dim \$input[7]

\$prog = StringSplit("my.exe,your.exe,our.exe,ie.exe,new.exe,autoit.exe" , ",")

for \$x = 1 to \$prog[0]
\$input[\$x] = InputBox("Test " & \$x, \$prog[\$x])
Next

; later

for \$t = 1 to \$prog[0]
if \$input[\$t] <> "" Then
; Run(\$prog[\$t]
MsgBox(0,"Test", \$prog[\$t])
EndIf
Next```

8)

##### Share on other sites

Okay, I think I am getting close. Think...

Question:

Is there a way to total how many variables are True (Greater than 0)?

For instance, I have 6 variables that the user inputs. If 3 are True (or Greater than 0), is there a way (command) that will 'Return' the number 3? Likewise, if all 6 are True, that it will return the number 6?

##### Share on other sites

Okay, I think I am getting close. Think...

Question:

Is there a way to total how many variables are True (Greater than 0)?

For instance, I have 6 variables that the user inputs. If 3 are True (or Greater than 0), is there a way (command) that will 'Return' the number 3? Likewise, if all 6 are True, that it will return the number 6?

If you use the select case example in my shippet above, an array element will only be assigned if the variable is true, so since \$myArray[0] is the count of the array elements \$myArray[0] -1 would be the count of the true variables.

##### Share on other sites

• Moderators

If you use the select case example in my shippet above, an array element will only be assigned if the variable is true, so since \$myArray[0] is the count of the array elements \$myArray[0] -1 would be the count of the true variables.

FYI: Your example has a couple of issues...

1. A variable is off \$C <<

2. \$ReturnValue will always = the last element value of the array (Maybe you meant \$ReturnValue &= \$MyArray[\$i] or \$ReturnValue = \$ReturnValue & \$MyArray[\$i]).

Try this lilmike

```Local \$MyArray[7] = ['', 'John', '', 'Mary', 'were', '', 'crazy']

\$Returned_Number_Of_Elements_Not_Empty = GetReturnNumber(\$MyArray)

MsgBox(0, 'Test', 'The Total Number Of Elements Used Was: ' & \$Returned_Number_Of_Elements_Not_Empty)

Func GetReturnNumber(\$avArray)
Local \$ReturnValue = ''
For \$i = 1 To UBound(\$avArray) - 1
If \$avArray[\$i] <> '' Then \$ReturnValue = \$ReturnValue + 1
Next
Return \$ReturnValue
EndFunc```

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

FYI: Your example has a couple of issues...

1. A variable is off \$C <<

2. \$ReturnValue will always = the last element value of the array (Maybe you meant \$ReturnValue &= \$MyArray[\$i] or \$ReturnValue = \$ReturnValue & \$MyArray[\$i]).

I was only attempting to show him how to get A return value from the example, not how to utilize or combine the values, since from his example I did not know exactly what his intentional use of the data was.
##### Share on other sites

To everyone, I have been thinking about your examples. And I have been trying to read up and better understand arrays. But, I have a thick skull, so its taking some time. Thanks for your patience.

I just can't seem to bridge the gap and solidify what to do here. To give more detail to what the script will do: 6 InputBoxes from GUI (numbers >= 0) will determine which of the 6 functions to activate and assign a value in that function. The trick is that the value in the function is determined by rank.

For example, if the 6 InputBoxes receive: {1,2,3,4,5,6,} then all 6 variables are True. Then all 6 functions are called. Most importantly there is a variable in those functions, that is determined by how many InputBoxes were True or >0. If \$A is True, it will always receive '1', if not then whatever next 'highest ranking' variable is true will receive '1'.

I wish I was better able to explain this earlier. Here is a bit of code that is in each function.

```;Edit Description
\$o_SearchForm = _IEFormGetObjByIndex (\$o_IE, 0)
\$o_Keywords = _IEFormElementGetObjByIndex (\$o_SearchForm, "description" & \$RANK)```
##### Share on other sites

• Moderators

Well short of writing it all out for you, and since you still are not providing ANY code of your own (Effort and Failure):

```Local \$MyArray[7]
\$MyArray[1] = InputBox('One', 'Enter Info', '', '', 100, 80)
\$MyArray[2] = InputBox('Two', 'Enter Info', '', '', 100, 80)
\$MyArray[3] = InputBox('Three', 'Enter Info', '', '', 100, 80)
\$MyArray[4] = InputBox('Four', 'Enter Info', '', '', 100, 80)
\$MyArray[5] = InputBox('Five', 'Enter Info', '', '', 100, 80)
\$MyArray[6] = InputBox('Six', 'Enter Info', '', '', 100, 80)

\$Returned_Number_Of_Elements_Not_Empty = GetReturnNumber(\$MyArray)

MsgBox(0, 'Test', \$Returned_Number_Of_Elements_Not_Empty)

Func GetReturnNumber(\$avArray)
Local \$ReturnValue = ''
Local \$Count = ''
For \$i = 1 To UBound(\$avArray) - 1
If \$avArray[\$i] <> '' Then
\$ReturnValue = \$ReturnValue & '\$MyArray[' & \$i & ']  =  ' & \$avArray[\$i] & @LF
\$Count += 1
EndIf
Next
Return 'There were ' & \$Count & ' True Elements, Info Listed Below:' & @CRLF & StringTrimRight(\$ReturnValue, 1)
EndFunc```

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...