Jump to content

Whats the Math ?


rasterscan
 Share

You are about to reply to a thread that has been inactive for 768 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi folks. I have a set of results, integers 24 , 36, 48 and 52.

What math would I use to select, or winkle out, the highest number in a set of results ? So the highest number can be declared the winner. Does that even make sense.

 

Edited by rasterscan
Link to comment
Share on other sites

list MyNums = [24,36,48,52];

default
{
     state_entry()
     {
          integer iMax;
          integer i;
          while ( i < llGetListLength(MyNums) )
          {
               if ( llList2Integer(MyNums,i) >= iMax)
               {
                     iMax = llList2Integer(MyNums,i);
               }
               ++i;
          }
          llSay(0,"The largest number is " + (string)iMax+ ".");
     }
}

Not optimized, but simple.

  • Like 1
Link to comment
Share on other sites

sometimes we want to get the index of the highest number when there is a avatar associated with the high score

in this case then

integer high_score;
integer index_of_winner;

integer i;

for (i = 0; i < llGetListLength(scores); i++)
{
    integer this = llList2Integer(scores, i);
    if (this >= high_score)
    {
      high_score = this;
      index_of_winner = i;
    }
}

llOwnerSay( "The winner is avatar no. " + (string)index_of_winner +
            " with a score of " + (string)high_score );

 

  • Like 1
Link to comment
Share on other sites

2 hours ago, Sloverdrive said:

You should use llListStatistics() for that.

 

On 4/24/2022 at 2:18 AM, Rolig Loon said:

llSay(0, "The largest number is " + (integer) llListStatistics(LIST_STAT_MAX, MyNums) + ".");

😉

🙂

Sorry.
I had missed your second post.😖

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 768 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...