FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour intercept repeated values in an array
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
intercept repeated values in an array
Posted: Mon Oct 24, 2022 07:41 AM
I have a cicle :

Code (fw): Select all Collapse
local nvalore,ntotale,n.k
local nat
local aTmp:={}

nValore := 1
   For n= 1 to 90
        For k= 1 to 90
              nTotale  := EstrattoSumDist(n,k,1)      //sample n+k 
                      If  nTotale==nvalore
                               [b] nAt := AScan( aTmp, { |a|  a[1]  = n  .or.  a[2]  = n} )[/b]
                                  if nAt == 0
                                          aadd(aTmp,{n,k})
                                  else
                                        HB_ADel( aTmp, nAt, .t. )
                                 Endif
                  Endif
            next
         next


why not run ok ?
it add repeated value into array
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: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: intercept repeated values in an array
Posted: Mon Oct 24, 2022 03:41 PM
Code (fw): Select all Collapse
// C:\FWH..\SAMPLES\CICLO.PRG

#include "FiveWin.ch"

FUNCTION Main()

   // LOCAL nvalore, ntotale, n.k // <- ERROR.
   LOCAL nvalore, ntotale, n, k
   LOCAL nat
   LOCAL aTmp := {}

   nValore := 0
   ntotale := 0

   FOR n = 1 TO 05 // 90 // Only test

      FOR k = 1 TO 05 //90 // Only test

         nTotale := EstrattoSumDist( n, k, 1 ) //sample n+k

         IF nTotale == nvalore

            nAt := AScan( aTmp, { |a| a[1] = n .OR. a[2] = n } )

            IF nAt == 0

               aAdd( aTmp, { n, k } )

            ELSE

               HB_ADel( aTmp, nAt, .T. )

            ENDIF

         ENDIF

      NEXT k

   NEXT n

RETURN NIL

FUNCTION EstrattoSumDist( n, k, nn )

   // ? n, k, nn

   ? n + k

RETURN NIL

// FIN / END


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: intercept repeated values in an array
Posted: Tue Oct 25, 2022 09:07 AM
karinha wrote:
Code (fw): Select all Collapse
// C:\FWH..\SAMPLES\CICLO.PRG

#include "FiveWin.ch"

FUNCTION Main()

   // LOCAL nvalore, ntotale, n.k // <- ERROR.
   LOCAL nvalore, ntotale, n, k
   LOCAL nat
   LOCAL aTmp := {}

   nValore := 0
   ntotale := 0

   FOR n = 1 TO 05 // 90 // Only test

      FOR k = 1 TO 05 //90 // Only test

         nTotale := EstrattoSumDist( n, k, 1 ) //sample n+k

         IF nTotale == nvalore

            nAt := AScan( aTmp, { |a| a[1] = n .OR. a[2] = n } )

            IF nAt == 0

               aAdd( aTmp, { n, k } )

            ELSE

               HB_ADel( aTmp, nAt, .T. )

            ENDIF

         ENDIF

      NEXT k

   NEXT n

RETURN NIL

FUNCTION EstrattoSumDist( n, k, nn )

   // ? n, k, nn

   ? n + k

RETURN NIL

// FIN / END


Regards, saludos.


your test not run
the array aTmp is Empty

my test



With the sum the nvalore must be min. 3 and not 1 sample 1+2 = 3

as you can see on picture the number 1 and 2 are repeated


Code (fw): Select all Collapse
#include "fivewin.ch"


Function test()
    local aTmp:={}
    local nAt
    local nTotale
    local nValore := 3

     For n= 1 to 90
        For k= 1 to 90
              nTotale  :=   k+n 
              If  nTotale=nvalore
                  /*  nAt := AScan( aTmp, { |a| a[1] = n .or. a[2] = n} )

                 if nAt == 0
                    */
                        aadd(aTmp,{n,k})
                     /* else
                       HB_ADel( aTmp, nAt, .t. )
                     Endif */
                  Endif
            next
         next

      xbrowser aTmp
   return nil
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: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: intercept repeated values in an array
Posted: Tue Oct 25, 2022 09:14 AM
Now I make another test But I believe it is not correct

Code (fw): Select all Collapse
Function test()
    local aTmp:={}
    local nAt
    local nTotale
    local nValore := 3

     For n= 1 to 90
        For k= 1 to 90
              nTotale  :=   k+n 
              If  nTotale=nvalore
                    nAt := AScan( aTmp, { |a| a[1] = n .or. a[2] = n} )
                                  aadd(aTmp,{n,k,nAt})
                  Endif
            next
         next

//erased repeated

         for t= 1 to len(aTmp)
                  If aTmp[t][3]=0
                       HB_ADel( aTmp, t, .t. )
                    Endif
           next


      xbrowser aTmp
   return nil
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: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: intercept repeated values in an array
Posted: Tue Oct 25, 2022 10:01 AM
Silvio, y crear un nuevo arreglo no?
Code (fw): Select all Collapse
#include 'fivewin.ch'

Function test()
    local aTmp:={}, aResu := {}
    local nAt
    local nTotale
    local nValore := 9

     For n= 1 to 90
        For k= 1 to 90
              nTotale  :=   k+n
              If  nTotale=nvalore
                    nAt := AScan( aTmp, { |a| a[1] = n .or. a[2] = n} )
                                  aadd(aTmp,{n,k,nAt})
                  Endif
            next
         next

//erased repeated

         for t= 1 to len(aTmp)
                  If aTmp[t][3]=0
                       Aadd( aResu, aTmp[t] )
                    Endif
           next


      xbrowser aResu
   return nil
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: intercept repeated values in an array
Posted: Wed Oct 26, 2022 08:04 AM
cmsoft wrote:Silvio, y crear un nuevo arreglo no?
Code (fw): Select all Collapse
#include 'fivewin.ch'

Function test()
    local aTmp:={}, aResu := {}
    local nAt
    local nTotale
    local nValore := 9

     For n= 1 to 90
        For k= 1 to 90
              nTotale  :=   k+n
              If  nTotale=nvalore
                    nAt := AScan( aTmp, { |a| a[1] = n .or. a[2] = n} )
                                  aadd(aTmp,{n,k,nAt})
                  Endif
            next
         next

//erased repeated

         for t= 1 to len(aTmp)
                  If aTmp[t][3]=0
                       Aadd( aResu, aTmp[t] )
                    Endif
           next


      xbrowser aResu
   return nil

As I wrote on private mail the problem is another
for the two dimensional array i solved

Code (fw): Select all Collapse
For n= 1 to 90
        For k= 1 to 90
              nTotale  := Calc_Ambi_Sum_dist(n,k,ntipo)
              If  nTotale=nvalore
                    nAt := AScan( aTmp, { |a| a[1] = n .or. a[2] = n} )
                    If nAt == 0
                       aadd(aTmp,{n,k})
                    Endif
                  Endif
            next
         next
Code (fw): Select all Collapse
Function Calc_Ambi_Sum_dist(n1,n2,nTipo)
//---------------------------------------
   local nNum:=0
   local nTemp:=0
   Do case
      case nTipo= 1 // suma ciclométrica      ok
          nTemp:= n1+n2
          If nTemp > 90
            nTemp:= ntemp-90      //el exterior 90
          Endif
       case nTipo= 2 //distancia ciclométrica    ok
          IF n2>n1
             nTemp:= n2-n1
          else
             nTemp:= n1-n2
          Endif
          If nTemp > 45          //   el exterior 45
             nTemp:= 90-nTemp
          Endif
       Case nTipo= 3  //suma matemática        ok
          nTemp:= n1+n2

       case ntipo = 4 // distancia matemática     ok
            IF n2>n1
             nTemp:= n2-n1
          else
             nTemp:= n1-n2
          Endif

     Endcase
     nNum := ntemp
     return nNum

for the three-dimensional array I find it difficult to find the numbers to associate

I explain you

1) I speak of two numbers because in the Italian lottery two numbers are equal to both
2) I speak of three numbers because in the Italian lottery three numbers are equal to three

the calculations are:
1) cyclometric sum
2) cyclometric distance
3) math addition
4) mathematical distance

for the cyclometric sum it is always necessary to subtract 90 if the sum exceeds 90

The cyclometric distance between two numbers is obtained by calculating the arithmetic difference (major minus minor); if the result exceeds "the limit" 45, the latter is subtracted from the 90 set.

The mathematical distance between two numbers is obtained by calculating the arithmetic difference (major minus minor); if the result exceeds "the limit" 90, the latter is subtracted from the 90 set.



for l'array with three numbers to create this cycle

Code (fw): Select all Collapse
 For n= 1 to 90
         For k= 1 to 90
            For j= 1 to 90
              nTotale  :=      Calc_Terni_Sum_dist(n,k,j,ntipo)
              If  nTotale=nvalore
                 nAt := AScan( aTmp, { |a| a[1] = n .and. a[2] = n .or.;
                                           a[2] = n .and. a[3] = n} )
                    If nAt == 0
                       aadd(aTmp,{n,k,j})
                    Endif
                  Endif
            next
         next
      next
and created this other function for the calculation but it is wrong
Code (fw): Select all Collapse
 Function Calc_Terni_Sum_dist(n1,n2,n3,nTipo)
//---------------------------------------
   local nNum:=0
   local nTemp:=0
   Do case
      case nTipo= 1 // suma ciclométrica      ok
         nTemp:= n1+n2+n3

          If nTemp > 90
            nTemp:= ntemp-90      //el exterior 90
         Endif

       case nTipo= 2 //distancia ciclométrica    ok

          IF n1 > n2  .or. n1 >n3
            nTemp:= n1-n2-n3
          elseif n2 > n1  .or. n2 >n3
            nTemp:= n2-n3-n1
          elseif n3 > n1  .or. n3 > n2
            nTemp:= n3-n1-n2
          Endif



          If nTemp > 45          //   el exterior 45
             nTemp:= 90-nTemp
          Endif

       Case nTipo= 3  //suma matemática        ok
          nTemp:= n1+n2

       case ntipo = 4 // distancia matemática     ok
             IF n1 > n2  .or. n1 >n3
            nTemp:= n1-n2-n3
          elseif n2 > n1  .or. n2 >n3
            nTemp:= n2-n3-n1
          elseif n3 > n1  .or. n3 > n2
            nTemp:= n3-n1-n2
          Endif

     Endcase
     nNum := ntemp
 return nNum
how could i solve?
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