Hello,
I'm trying to pick the Max Integer of an Integer Array. As you can see in the link below, I wasn't sure how to setup the Integer Array with the Maximum Integer function. Would anyone be able to assist me with what I should do?
Thanks
It appears you are trying to find the max value of an array.
Since your array is small, you should do the bruteforce method of simply looping through the array, comparing the current max value with each value in the array (current max starts at 0, or some really large negative number).
Use a linear search modified for finding and returning the largest element. Here is a galaxy style example.
constintN=16;int[N]elements;inti;intmax;// initialize elements here// the first element is the first encountered value so used to initialize the search statei=1;max=0;// perform maximum searchwhile(i<N){if(elements[i]>elements[max]){max=i;}i+=1}// max now contains the index of the maximum element
It works for finding the maximum in practically any number of elements. Only issue is the O(n) complexity which in performance sensitive situations could cause problems. If you want a faster solution you will need to use pre-ordered lists.
Thanks for attempting to help! Thing is I'm not really fond of this type of coding as I'm just trying to figure out a way using the Variable find the Maximum Integer in an Array. I'm unsure if this would work: "Variable - Set Local Winning Player = (Max(0, Local Player Scores[(Picked player)]))"
A little extra information would be I'm using this to determine the highest scoring Player and set that Player with the highest score to equal variable Winner.
I'm unsure if this would work: "Variable - Set Local Winning Player = (Max(0, Local Player Scores[(Picked player)]))"
It almost certainly will not work. Galaxy is not a functional programming language.
You will need to set up a loop to test each element in the array. Convert the extract I gave into GUI and it will work. This is basically the same as what LucidIguana gave except it results in the player index rather than the amount.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hello, I'm trying to pick the Max Integer of an Integer Array. As you can see in the link below, I wasn't sure how to setup the Integer Array with the Maximum Integer function. Would anyone be able to assist me with what I should do? Thanks
http://peeeq.de/gui.php?id=3817
What exactly are you trying to do? Find the highest value among entries in the array?
It appears you are trying to find the max value of an array.
Since your array is small, you should do the bruteforce method of simply looping through the array, comparing the current max value with each value in the array (current max starts at 0, or some really large negative number).
@LucidIguana: Go
Yes, I'm trying to find the highest value in the array.
@ArcaneDurandel: Go
So I should do this?
"Variable - Set Local Winning Player = (Max(0, Local Player Scores[(Picked player)]))"
Use a linear search modified for finding and returning the largest element. Here is a galaxy style example.
It works for finding the maximum in practically any number of elements. Only issue is the O(n) complexity which in performance sensitive situations could cause problems. If you want a faster solution you will need to use pre-ordered lists.
@ImperialGood: Go
Thanks for attempting to help! Thing is I'm not really fond of this type of coding as I'm just trying to figure out a way using the Variable find the Maximum Integer in an Array. I'm unsure if this would work: "Variable - Set Local Winning Player = (Max(0, Local Player Scores[(Picked player)]))"
In the GUI, I'd do something like this:
Variables:
Actions:
For each integer (i) between 0 and 13:
@LucidIguana: Go
This actually could work and I actually am going to use it. Still hoping if anyone could show me a way through the function "Maximum (Integer)".
A little extra information would be I'm using this to determine the highest scoring Player and set that Player with the highest score to equal variable Winner.
It almost certainly will not work. Galaxy is not a functional programming language.
You will need to set up a loop to test each element in the array. Convert the extract I gave into GUI and it will work. This is basically the same as what LucidIguana gave except it results in the player index rather than the amount.