Sign in to follow this  
Followers 0
dantay9

[Solved] Array Trouble

4 posts in this topic

#1 ·  Posted (edited)

I hate solving for trinomials, so I thought I'd make a script to do it for me. I am having trouble getting the correct values assigned to the correct dimension in the correct array. I want the array in this format:

$Array[factor group #][1 for first # in group; 2 for second #] = 1st or 2nd number in group

As an example, for the squared term in 2x^2+2x+1=0, I want:

$Array[1][1] = 1

$Array[1][2] = 2

$Array[2][1] = 2

$Array[2][2] = 1

I hope I made this clear enough. If there is already an example of this on the forum and I missed it, then please tell me. Thanks in advance.

Edited by dantay9

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites



I hate solving for trinomials, so I thought I'd make a script to do it for me. I am having trouble getting the correct values assigned to the correct dimension in the correct array. I want the array in this format:

$Array[factor group #][1 for first # in group; 2 for second #] = 1st or 2nd number in group

As an example, for the squared term in 2x^2+2x+1=0, I want:

$Array[1][1] = 1

$Array[1][2] = 2

$Array[2][1] = 2

$Array[2][2] = 1

I hope I made this clear enough. If there is already an example of this on the forum and I missed it, then please tell me. Thanks in advance.

1) AutoIt arrays are 0-based, so your references should be [0][0] and [0][1], then [1][0] and [1][1], etc.

2) Trinomial means "three terms" not three factors, so what do you mean by "factor group"?

3) What do "first #" and "second #" mean? The first term is 2x^2, so which of the "groups" you gave represents that? The second term is 2x, and I guess the second example you gave matches (2x^1). The third term (1) is not represented at all in your example.

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

1) Sorry. My mistake. I do need the arrays to be zero based. That is not a problem.

2) The factors of 4 are 1, 2, and 4. The factor groups I am referring to are 1 & 4 and 2 & 2. The group number is just an index number. The first dimension is just an index so I can sort the groups.

3) The first and second number are referring to the groups. For example, 1 is the first number and 4 is the second number (in the example above).

Here is an example based on the factors of 6. I want this in the array:

$Array[0][1] = 1

$Array[0][2] = 6

$Array[1][1] = 2

$Array[1][2] = 3


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

Here is what I was looking for. Sorry about my post being hard to understand.

$AllSquaredTermFactors = SquareFactors($Trinomial); contains all groups of factors
ReDim $FactorGroups[UBound($AllSquaredTermFactors)][2]
$x = 0
For $element In $AllSquaredTermFactors
    $TempArray = StringSplit($element, ",", 2)
    $FactorGroups[$x][0] = $TempArray[0]
    $FactorGroups[$x][1] = $TempArray[1]
    $x += 1
Next
_ArrayDisplay($FactorGroups)

Func GetFactors($Number)
    Local $x
    Local $Factors = ""
    Local $SquareRoot = Ceiling(Sqrt(Abs($Number)))
    For $x = 1 To $SquareRoot
        If Mod($Number, $x) = 0 Then
            $Factors = $Factors & $x & "," & $Number / $x & "|"
        EndIf
    Next
    $Factors = StringTrimRight($Factors, 1)
    $AFactors = StringSplit($Factors, "|", 2)
    Return $AFactors
EndFunc  ;==>GetFactors
Func SquareFactors($Function)
    Local $Position, $SquaredTerm, $Factors
    $Position = StringInStr($Function, "x^2")
    If $Position <= 1 Then
        $SquaredTerm = "1"
    Else
        $SquaredTerm = StringLeft($Trinomial, $Position - 1)
    EndIf
    $Trinomial = StringTrimLeft($Function, $Position)
    $SquaredTerm = Number($SquaredTerm)
    $Factors = GetFactors($SquaredTerm)
    Return $Factors
EndFunc  ;==>SquareFactors

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0