Jump to content

comparing multiple number values


gcue
 Share

Recommended Posts

i have an array of numbers

whats the most efficient way of comparing all of them to find the largest number?

was trying to use a for loop for a faster/more efficient compare but cant figure out the logic

For $x = 1 To 4
            If $aINIs[$x][1] > $aINIs[$x + 1][1] Then
                $largest = $x
            Else
                $largest = $x + 1
            EndIf
        Next

msgbox(0,"", $largest & " is the largest")

thanks =)

Edited by gcue
Link to comment
Share on other sites

If you wanted to do it in the least lines of Autoit code, you could probably just use _ArraySort and then check the last (or first, depending upon sort order) element for your value.

Of course, that method destroys the original order of your array, and behind the scenes is doing a ton more processing than is necessary. You were on the right track to begin with, with something like:

$largest = 0
For $x = 1 To UBound($aINI, 1) - 1
    If $aINIs[$x][1] > $aINIs[$x - 1][1] Then $largest = $x
Next
MsgBox(0,"", "Index " & $largest & " is the largest, with a value of: " & $aINIs[$largest][1])
Link to comment
Share on other sites

thanks for the response spiff

that doesn't seem to be working properly though..

it says index 5 value is the largest when its not

http://www.postimage.org/image.php?v=gxyZHBA

Edited by gcue
Link to comment
Share on other sites

$largest = 0
For $x = 0 To UBound($aINI, 1) - 1
    If $aINIs[$x][1] > $largest Then $largest = $x
Next
MsgBox(0,"", "Index " & $largest & " is the largest, with a value of: " & $aINIs[$largest][1])

Oops,you're right, $largest needs going thru array indexing.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Pardon me, the Mark 1 Eyeball failed me.

$largest = 0
For $x = 1 To UBound($aINIs, 1) - 1
    If $aINIs[$x][1] > $aINIs[$largest][1] Then $largest = $x
Next
MsgBox(0,"", "Index " & $largest & " is the largest, with a value of: " & $aINIs[$largest][1])
Edited by Spiff59
Link to comment
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
 Share

  • Recently Browsing   0 members

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