Jump to content
Sign in to follow this  
lilx

Finding the Highest number

Recommended Posts

lilx

hello,

well i hope this is a little brain buster for you guys, well it is for me :)

i am simple generating some numbers and all unique numbers are in a variable.

now i was looking for a simple way for finding the highest value, how easy it must be for the eye for finding the highest number.

i can't think for a simple way of looking for the highest number in code for 18 unique numbers.

i hope you guys can help me.

greeting,

lilx

Share this post


Link to post
Share on other sites
NBJ

A couple of ways:

put them into an array and use _arraysort

Use Max()

Any other ideas?

Share this post


Link to post
Share on other sites
lilx

hey sorry to ask a question again,

but got it working with the example showed in the help.

but this show my only the highest number, is het possible to see wich var it was?

Share this post


Link to post
Share on other sites
BrettF
lilx

well the code is really noobish but i was trying to give someone a random count example.

now i am just curious how random the random really is :)

#include <Array.au3>

Dim $loops = 0
Dim $getal1 = 0, $getal2 = 0, $getal3 = 0, $getal4 = 0, $getal5 = 0, $getal6 = 0, $getal7 = 0, $getal8 = 0, $getal9 = 0, $getal10 = 0
Dim $getal11 = 0, $getal12 = 0, $getal13 = 0, $getal14 = 0, $getal15 = 0, $getal16 = 0, $getal17 = 0, $getal18 = 0, $getal19 = 0, $getal20 = 0
Dim $getal21 = 0, $getal22 = 0, $getal23 = 0, $getal24 = 0, $getal25 = 0, $getal26 = 0, $getal27 = 0, $getal28 = 0, $getal29 = 0, $getal30 = 0
Dim $getal31 = 0, $getal32 = 0, $getal33 = 0, $getal34 = 0, $getal35 = 0, $getal36 = 0, $getal37 = 0, $getal38 = 0, $getal39 = 0, $getal40 = 0
Dim $getal41 = 0, $getal42 = 0, $getal43 = 0, $getal44 = 0, $getal45 = 0

Do
    $getal = Random ( 1, 45, 1 )
    ;ConsoleWrite ( $getal )
        Select
            Case $getal = 1
                $getal1 = $getal1 + 1
            Case $getal = 2
                $getal2 = $getal2 + 1
            Case $getal = 3
                $getal3 = $getal3 + 1
            Case $getal = 4
                $getal4 = $getal4 + 1
            Case $getal = 5
                $getal5 = $getal5 + 1
            Case $getal = 6
                $getal6 = $getal6 + 1
            Case $getal = 7
                $getal7 = $getal7 + 1
            Case $getal = 8
                $getal8 = $getal8 + 1
            Case $getal = 9
                $getal9 = $getal9 + 1
            Case $getal = 10
                $getal10 = $getal10 + 1
            Case $getal = 11
                $getal11 = $getal11 + 1
            Case $getal = 12
                $getal12 = $getal12 + 1
            Case $getal = 13
                $getal13 = $getal13 + 1
            Case $getal = 14
                $getal14 = $getal14 + 1
            Case $getal = 15
                $getal15 = $getal15 + 1
            Case $getal = 16
                $getal16 = $getal16 + 1
            Case $getal = 17
                $getal17 = $getal17 + 1
            Case $getal = 18
                $getal18 = $getal18 + 1
            Case $getal = 19
                $getal19 = $getal19 + 1
            Case $getal = 20
                $getal20 = $getal20 + 1
            Case $getal = 21
                $getal21 = $getal21 + 1
            Case $getal = 22
                $getal22 = $getal22 + 1
            Case $getal = 23
                $getal23 = $getal23 + 1
            Case $getal = 24
                $getal24 = $getal24 + 1
            Case $getal = 25
                $getal25 = $getal25 + 1
            Case $getal = 26
                $getal26 = $getal26 + 1
            Case $getal = 27
                $getal27 = $getal27 + 1
            Case $getal = 28
                $getal28 = $getal28 + 1
            Case $getal = 29
                $getal29 = $getal29 + 1
            Case $getal = 30
                $getal30 = $getal30 + 1
            Case $getal = 31
                $getal31 = $getal31 + 1
            Case $getal = 32
                $getal32 = $getal32 + 1
            Case $getal = 33
                $getal33 = $getal33 + 1
            Case $getal = 34
                $getal34 = $getal34 + 1
            Case $getal = 35
                $getal35 = $getal35 + 1
            Case $getal = 36
                $getal36 = $getal36 + 1
            Case $getal = 37
                $getal37 = $getal37 + 1
            Case $getal = 38
                $getal38 = $getal38 + 1
            Case $getal = 39
                $getal39 = $getal39 + 1
            Case $getal = 40
                $getal40 = $getal40 + 1
            Case $getal = 41
                $getal41 = $getal41 + 1
            Case $getal = 42
                $getal42 = $getal42 + 1
            Case $getal = 43
                $getal43 = $getal43 + 1
            Case $getal = 44
                $getal44 = $getal44 + 1
            Case $getal = 45
                $getal45 = $getal45 + 1
        EndSelect
    $loops = $loops + 1
Until $loops = 32000

Local $avArray = StringSplit($getal1 & "|" & $getal2 & "|" & $getal3 & "|" & $getal4 & "|" & $getal5 & "|" & $getal6 & "|" & $getal7 & "|" & $getal8 & "|" & $getal9 & "|" & $getal10 & "|" & _
                            $getal11 & "|" & $getal12 & "|" & $getal13 & "|" & $getal14 & "|" & $getal15 & "|" & $getal16 & "|" & $getal17 & "|" & $getal18 & "|" & $getal19 & "|" & $getal20 & "|" & _
                            $getal21 & "|" & $getal22 & "|" & $getal23 & "|" & $getal24 & "|" & $getal25 & "|" & $getal26 & "|" & $getal27 & "|" & $getal28 & "|" & $getal29 & "|" & $getal30 & "|" & _
                            $getal31 & "|" & $getal32 & "|" & $getal33 & "|" & $getal34 & "|" & $getal35 & "|" & $getal36 & "|" & $getal37 & "|" & $getal38 & "|" & $getal39 & "|" & $getal40 & "|" & _
                            $getal41 & "|" & $getal42 & "|" & $getal43 & "|" & $getal44 & "|" & $getal45, "|")

MsgBox(0,'Max Numeric value', _ArrayMax($avArray, 1, 1))
Edited by lilx

Share this post


Link to post
Share on other sites
martin

well the code is really noobish but i was trying to give someone a random count example.

now i am just curious how random the random really is ;)

#include <Array.au3>

Dim $loops = 0
Dim $getal1 = 0, $getal2 = 0, $getal3 = 0, $getal4 = 0, $getal5 = 0, $getal6 = 0, $getal7 = 0, $getal8 = 0, $getal9 = 0, $getal10 = 0
Dim $getal11 = 0, $getal12 = 0, $getal13 = 0, $getal14 = 0, $getal15 = 0, $getal16 = 0, $getal17 = 0, $getal18 = 0, $getal19 = 0, $getal20 = 0
Dim $getal21 = 0, $getal22 = 0, $getal23 = 0, $getal24 = 0, $getal25 = 0, $getal26 = 0, $getal27 = 0, $getal28 = 0, $getal29 = 0, $getal30 = 0
Dim $getal31 = 0, $getal32 = 0, $getal33 = 0, $getal34 = 0, $getal35 = 0, $getal36 = 0, $getal37 = 0, $getal38 = 0, $getal39 = 0, $getal40 = 0
Dim $getal41 = 0, $getal42 = 0, $getal43 = 0, $getal44 = 0, $getal45 = 0

Do
    $getal = Random ( 1, 45, 1 )
    ;ConsoleWrite ( $getal )
        Select
            Case $getal = 1
                $getal1 = $getal1 + 1
            Case $getal = 2
                $getal2 = $getal2 + 1
            Case $getal = 3
                $getal3 = $getal3 + 1
            Case $getal = 4
                $getal4 = $getal4 + 1
            Case $getal = 5
                $getal5 = $getal5 + 1
            Case $getal = 6
                $getal6 = $getal6 + 1
            Case $getal = 7
                $getal7 = $getal7 + 1
            Case $getal = 8
                $getal8 = $getal8 + 1
            Case $getal = 9
                $getal9 = $getal9 + 1
            Case $getal = 10
                $getal10 = $getal10 + 1
            Case $getal = 11
                $getal11 = $getal11 + 1
            Case $getal = 12
                $getal12 = $getal12 + 1
            Case $getal = 13
                $getal13 = $getal13 + 1
            Case $getal = 14
                $getal14 = $getal14 + 1
            Case $getal = 15
                $getal15 = $getal15 + 1
            Case $getal = 16
                $getal16 = $getal16 + 1
            Case $getal = 17
                $getal17 = $getal17 + 1
            Case $getal = 18
                $getal18 = $getal18 + 1
            Case $getal = 19
                $getal19 = $getal19 + 1
            Case $getal = 20
                $getal20 = $getal20 + 1
            Case $getal = 21
                $getal21 = $getal21 + 1
            Case $getal = 22
                $getal22 = $getal22 + 1
            Case $getal = 23
                $getal23 = $getal23 + 1
            Case $getal = 24
                $getal24 = $getal24 + 1
            Case $getal = 25
                $getal25 = $getal25 + 1
            Case $getal = 26
                $getal26 = $getal26 + 1
            Case $getal = 27
                $getal27 = $getal27 + 1
            Case $getal = 28
                $getal28 = $getal28 + 1
            Case $getal = 29
                $getal29 = $getal29 + 1
            Case $getal = 30
                $getal30 = $getal30 + 1
            Case $getal = 31
                $getal31 = $getal31 + 1
            Case $getal = 32
                $getal32 = $getal32 + 1
            Case $getal = 33
                $getal33 = $getal33 + 1
            Case $getal = 34
                $getal34 = $getal34 + 1
            Case $getal = 35
                $getal35 = $getal35 + 1
            Case $getal = 36
                $getal36 = $getal36 + 1
            Case $getal = 37
                $getal37 = $getal37 + 1
            Case $getal = 38
                $getal38 = $getal38 + 1
            Case $getal = 39
                $getal39 = $getal39 + 1
            Case $getal = 40
                $getal40 = $getal40 + 1
            Case $getal = 41
                $getal41 = $getal41 + 1
            Case $getal = 42
                $getal42 = $getal42 + 1
            Case $getal = 43
                $getal43 = $getal43 + 1
            Case $getal = 44
                $getal44 = $getal44 + 1
            Case $getal = 45
                $getal45 = $getal45 + 1
        EndSelect
    $loops = $loops + 1
Until $loops = 32000

Local $avArray = StringSplit($getal1 & "|" & $getal2 & "|" & $getal3 & "|" & $getal4 & "|" & $getal5 & "|" & $getal6 & "|" & $getal7 & "|" & $getal8 & "|" & $getal9 & "|" & $getal10 & "|" & _
                            $getal11 & "|" & $getal12 & "|" & $getal13 & "|" & $getal14 & "|" & $getal15 & "|" & $getal16 & "|" & $getal17 & "|" & $getal18 & "|" & $getal19 & "|" & $getal20 & "|" & _
                            $getal21 & "|" & $getal22 & "|" & $getal23 & "|" & $getal24 & "|" & $getal25 & "|" & $getal26 & "|" & $getal27 & "|" & $getal28 & "|" & $getal29 & "|" & $getal30 & "|" & _
                            $getal31 & "|" & $getal32 & "|" & $getal33 & "|" & $getal34 & "|" & $getal35 & "|" & $getal36 & "|" & $getal37 & "|" & $getal38 & "|" & $getal39 & "|" & $getal40 & "|" & _
                            $getal41 & "|" & $getal42 & "|" & $getal43 & "|" & $getal44 & "|" & $getal45, "|")

MsgBox(0,'Max Numeric value', _ArrayMax($avArray, 1, 1))

Wooow! You must really like typing :)

You must learn to use arrays and then with the time you save you will be abl eto conquer the world.

You could write your code like this

#include <Array.au3>

Dim $loops = 0
Dim $getall[45]


Do
    $getal1 = Random (0, 44, 1 )
    $getall[$getal1] += 1

    $loops = $loops + 1
Until $loops = 32000


MsgBox(0,'Max Numeric value', _ArrayMax($getall,1))

$highval = 0
$highIndex = -1

For $n = 0 to 44
    if $getall[$n] > $highval then
        $highval = $getall[$n]
        $highIndex = $n
    EndIf
Next
msgbox(262144, "Max val is", $highval & ", which is in $getall[" & $highIndex & "]")

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
lilx

Wooow! You must really like typing :)

You must learn to use arrays and then with the time you save you will be abl eto conquer the world.

You could write your code like this

#include <Array.au3>

Dim $loops = 0
Dim $getall[45]


Do
    $getal1 = Random (0, 44, 1 )
    $getall[$getal1] += 1

    $loops = $loops + 1
Until $loops = 32000


MsgBox(0,'Max Numeric value', _ArrayMax($getall,1))

$highval = 0
$highIndex = -1

For $n = 0 to 44
    if $getall[$n] > $highval then
        $highval = $getall[$n]
        $highIndex = $n
    EndIf
Next
msgbox(262144, "Max val is", $highval & ", which is in $getall[" & $highIndex & "]")

omg well, i was tryin to explain to a totally beginner.

but to be fair, i wouldn't have dun it like that if i was just doing it for me ;)

thank you very much B)

Edited by lilx

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.