FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour search highest digit in the array
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
search highest digit in the array
Posted: Wed Mar 09, 2022 12:24 PM
I have this array



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)
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 218
Joined: Mon Feb 07, 2022 09:54 PM
Re: search highest digit in the array
Posted: Wed Mar 09, 2022 08:00 PM
Hi Silvio,
here a quick function to fnd the max value in your array.
Code (fw): Select all Collapse
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
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: search highest digit in the array
Posted: Thu Mar 10, 2022 08:06 AM
Detlef wrote:Hi Silvio,
here a quick function to fnd the max value in your array.
Code (fw): Select all Collapse
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



thanks
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 218
Joined: Mon Feb 07, 2022 09:54 PM
Re: search highest digit in the array
Posted: Thu Mar 10, 2022 08:21 AM

But one problem.
If there are two cells with the same highest value.
Then you must decide which cell is the one you want.

Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: search highest digit in the array
Posted: Thu Mar 10, 2022 08:31 AM
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:= 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 ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 218
Joined: Mon Feb 07, 2022 09:54 PM
Re: search highest digit in the array
Posted: Thu Mar 10, 2022 09:53 AM
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 "="
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: search highest digit in the array
Posted: Thu Mar 10, 2022 12:04 PM

Silvio,

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

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: search highest digit in the array
Posted: Thu Mar 10, 2022 05:27 PM
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
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion