# Compare 6 numbers for the lowest or highest

## Recommended Posts

I am looking for an efficient way to compare 6 numbers and find out what the lowest and the highest are. I'm writing a dice roller and I want it to be able to apply functions to the lowest or highest roll, but I need to separate those rolls so I can do that. I looked through the math include and all I found was a way to compare two numbers, and modifying that for 6 would create a very convoluted mess, is there a better way?

[u]You can download my projects at:[/u] Pulsar Software

##### Share on other sites

Hi,

I don't have an example , but maybe you write the 6 numbers to an array and use _ArraySort() sort function in AutoIt help file under User Defined Functions ->Array Management ->_ArraySort.

Once you've sorted the array you can use first or last element in the array as the highest or lowest value

(depending on the way you sort the array, Descending or Ascending).

Good Luck

Cheers

##### Share on other sites

Try These:

They return the biggest, and the smallest of the 6 numbers.

Returns The Biggest:

```Func _GetBigNumber (\$1, \$2, \$3, \$4, \$5, \$6)
Local \$max = \$1
For \$i = 1 to 6
If \$max < Eval(\$i) Then
\$max = Eval(\$i)
EndIf
Next
Return \$max
ÌÍÌK ÌÍÌ  ÌÍÌË    ÌÍÍ  ÌÍÍK ÌÍÍBBSØØ[  ÌÍÛZ[H   ÌÍÌBBQÜ ÌÍÚHHHÈ
BBRY    ÌÍÛZ[    ÝÈ][
ÌÍÚJH[BBBIÌÍÛZ[H][
ÌÍÚJBBBQ[YBS^BT] ÌÍÛZ[[[oÝ÷ Ù­º¹ìav§jºÚËMújºÚË```

Hope it helps

EDIT: Spelling...

Edited by Bert

_ArraySort()

8)

##### Share on other sites

_ArraySort()

8)

It's kinda slow tho. Almost the same as doing

_Min(_Min(_Min(_Min(_Min(\$n1,\$n2),\$n3),\$n4),\$n5),\$n6)

_Max(_Max(_Max(_Max(_Max(\$n1,\$n2),\$n3),\$n4),\$n5),\$n6)

Bert's last function to return min/max runs twice faster...

Just sayin...

"be smart, drink your wine"

##### Share on other sites

I forgot to take something into account, I allow the user to select which dice are to be rolled. Meaning of the six dice, they can choose to roll die 1 and die 3. So what I really need now is a way to make the function that selects the lowest or highest number be able to tell which dice were selected and choose the lowest or highest of those.

if I use the function as Bert suggested, I'll get an error parsing function call because some of the variables won't exist if the user doesn't use all 6 dice.

Would the _ArraySort() function make that work better for what I need or is there a way to modify Bert's to make it more efficient?

Edited by maqleod

[u]You can download my projects at:[/u] Pulsar Software

##### Share on other sites

I forgot to take something into account, I allow the user to select which dice are to be rolled. Meaning of the six dice, they can choose to roll die 1 and die 3. So what I really need now is a way to make the function that selects the lowest or highest number be able to tell which dice were selected and choose the lowest or highest of those.

if I use the function as Bert suggested, I'll get an error parsing function call because some of the variables won't exist if the user doesn't use all 6 dice.

Would the _ArraySort() function make that work better for what I need or is there a way to modify Bert's to make it more efficient?

I guess if you just fill the other numbers with 0s???

##### Share on other sites

I guess if you just fill the other numbers with 0s???

but won't it then choose those as the lowest number?

[u]You can download my projects at:[/u] Pulsar Software

##### Share on other sites

but won't it then choose those as the lowest number?

I think he implied that you are able to modify the functions to take care about the special value 0 !??!

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

## 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