Page 1 of 1

search highest digit in the array

PostPosted: Wed Mar 09, 2022 12:24 pm
by Silvio.Falconi
I have this array

Image

How can I find the highest digit in the array?
example in this screen in the last line there is the value 663
the function should return me that in the combination (first column) the maximum output is 663 (9 column) and highlight it (bringing the cursor to that position)

Re: search highest digit in the array

PostPosted: Wed Mar 09, 2022 8:00 pm
by Detlef
Hi Silvio,
here a quick function to fnd the max value in your array.
Code: Select all  Expand view
FUNCTION aFindMax( xArray ) // xArray should be your array
LOCAL aVals := {;    //just for testing
                  { 0,  45,  29,  97, 472, 265, 127,   3, 123,  24,  11,  55 },;
                  { 0,  66, 104, 298,  79,  47,  12,  12,  90,  48, 130, 155 },;
                  { 0, 158,   7,   7,  95, 169,  86, 230, 148,  79, 446,  20 },;
                  { 0,  11,  17, 131, 422,  50, 204,  37,   5,  11,  48, 433 },;
                  { 0,  52,   6,  49, 312,  58, 128, 108, 284, 248,  92, 373 },;
                  { 0,  33,  30, 440, 451,  77,  60,  70, 227, 440,  31,  25 },;
                  { 0,  70, 134,   5,  60,  55,  11, 347,  22,  28, 549,  66 },;
                  { 0, 259,  58,  30,  18,  57,  91,  27, 126,  65,  78, 176 },;
                  { 0, 107,  42, 118,  94,  37,  49,  23, 623,  22,  19,  79 } ;
               }
LOCAL nRows := len( aVals )  
LOCAL nCols := len( aVals[1] )
LOCAL nR, nC
LOCAL nRmax := 0, nCmax := 0
LOCAL nMax  := 0

      for nR := 1 to nRows
         for nC := 2 to nCols
            if aVals[nR, nC] > nMax
               nMax := aVals[nR, nC]
               nRmax := nR
               nCmax := nC
            endif
         next
      next

      msginfo( nRmax ) //just for testing
      msginfo( nCmax ) //just for testing

RETURN ( { nRmax, nCmax } )    // Returns  array with row and col numbers of maximum
 

regards, Detlef

Re: search highest digit in the array

PostPosted: Thu Mar 10, 2022 8:06 am
by Silvio.Falconi
Detlef wrote:Hi Silvio,
here a quick function to fnd the max value in your array.
Code: Select all  Expand view
FUNCTION aFindMax( xArray ) // xArray should be your array
LOCAL aVals := {;    //just for testing
                  { 0,  45,  29,  97, 472, 265, 127,   3, 123,  24,  11,  55 },;
                  { 0,  66, 104, 298,  79,  47,  12,  12,  90,  48, 130, 155 },;
                  { 0, 158,   7,   7,  95, 169,  86, 230, 148,  79, 446,  20 },;
                  { 0,  11,  17, 131, 422,  50, 204,  37,   5,  11,  48, 433 },;
                  { 0,  52,   6,  49, 312,  58, 128, 108, 284, 248,  92, 373 },;
                  { 0,  33,  30, 440, 451,  77,  60,  70, 227, 440,  31,  25 },;
                  { 0,  70, 134,   5,  60,  55,  11, 347,  22,  28, 549,  66 },;
                  { 0, 259,  58,  30,  18,  57,  91,  27, 126,  65,  78, 176 },;
                  { 0, 107,  42, 118,  94,  37,  49,  23, 623,  22,  19,  79 } ;
               }
LOCAL nRows := len( aVals )  
LOCAL nCols := len( aVals[1] )
LOCAL nR, nC
LOCAL nRmax := 0, nCmax := 0
LOCAL nMax  := 0

      for nR := 1 to nRows
         for nC := 2 to nCols
            if aVals[nR, nC] > nMax
               nMax := aVals[nR, nC]
               nRmax := nR
               nCmax := nC
            endif
         next
      next

      msginfo( nRmax ) //just for testing
      msginfo( nCmax ) //just for testing

RETURN ( { nRmax, nCmax } )    // Returns  array with row and col numbers of maximum
 

regards, Detlef


Run good

Image

thanks

Re: search highest digit in the array

PostPosted: Thu Mar 10, 2022 8:21 am
by Detlef
But one problem.
If there are two cells with the same highest value.
Then you must decide which cell is the one you want.

Re: search highest digit in the array

PostPosted: Thu Mar 10, 2022 8:31 am
by Silvio.Falconi
Detlef wrote:But one problem.
If there are two cells with the same highest value.
Then you must decide which cell is the one you want.


I make statistical calculations on an archive of lottery extractions from 1939 to today ( here in Italy)
I made on 91 the first prg on clipper 87 and now I rewrite the prg with fwh with many problems

On Picture I perform the calculation of the tens for what concerns the Terni (ie the output of 3 numbers), these are classical groupings

Detlef,
for the same value it is a problem, I don't know how to do it and anyway I think it always takes the last calculated?

I made
nRowSelect:=Colorize_Max(oBrw,RGB( 255, 0,0 ),RGB( 252, 235, 220 ))
oBrw:KeyNo:= nRowSelect

static Function Colorize_Max(oBrw,nColor1,nColor2)
local avals:= oBrw:aArraydata
local atest:= aFindMax( aVals )
local nRow:= atest[1]
local nCol:= atest[2]
oBrw:aCols[nCol]:bClrStd := {|| { CLR_BLACK,IIf(oBrw:nArrayAt=nRow, nColor1,nColor2) } }
return nRow

any suggestion ?

Re: search highest digit in the array

PostPosted: Thu Mar 10, 2022 9:53 am
by Detlef
Silvio,

if you want to have the last of same values you must change only one line of my function.

if aVals[nR, nC] >= nMax // instead of only "="

Re: search highest digit in the array

PostPosted: Thu Mar 10, 2022 12:04 pm
by Marc Venken
Silvio,

Just curious, Did it make any difference in playing lotto with a statistical program ? I hope for you....

Re: search highest digit in the array

PostPosted: Thu Mar 10, 2022 5:27 pm
by Silvio.Falconi
Marc Venken wrote:Silvio,

Just curious, Did it make any difference in playing lotto with a statistical program ? I hope for you....


help me sometimes