Hello,
I have a series of variables that contain integers var1, var2, .... and would like to find the largest, 2nd largest, 3rd largest, etc.
Thank you.
Finding 2nd and 3rd largest integers in a set
- Masonjar13
- Posts: 1555
- Joined: 20 Jul 2014, 10:16
- Location: Не Россия
- Contact:
Re: Finding 2nd and 3rd largest integers in a set
You would need to append the variables first, but Sort is probably what you're looking for. If you really want to keep them separate, consider making a function that will iterate through all the variables and compare. You can get the whole list of vars into a function by either using an object or variadic parameter.
Re: Finding 2nd and 3rd largest integers in a set
If you map the integer into an AHK array, then map the name of the integer as the value, you can enumerate through the array and get the variables in order.
The reason this works is because AutoHotkey will auto sort objects in alphabetical and numeric order. (Using a binary tree I think.)
Code: Select all
var1 := 67
var2 := 45
var3 := 77
var4 := 04
array := []
loop 4
array[var%A_Index%] := "var" . A_Index
MsgBox % "1st largest: " array.MaxIndex() " is " array.pop()
MsgBox % "2nd largest: " array.MaxIndex() " is " array.pop()
MsgBox % "3rd largest: " array.MaxIndex() " is " array.pop()
Who is online
Users browsing this forum: No registered users and 311 guests