intercept repeated values in an array

intercept repeated values in an array

Postby Silvio.Falconi » Mon Oct 24, 2022 7:41 am

I have a cicle :

Code: Select all  Expand view

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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7034
Joined: Thu Oct 18, 2012 7:17 pm

Re: intercept repeated values in an array

Postby karinha » Mon Oct 24, 2022 3:41 pm

Code: Select all  Expand view

// 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
User avatar
karinha
 
Posts: 7794
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: intercept repeated values in an array

Postby Silvio.Falconi » Tue Oct 25, 2022 9:07 am

karinha wrote:
Code: Select all  Expand view

// 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

Image

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: Select all  Expand view

#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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7034
Joined: Thu Oct 18, 2012 7:17 pm

Re: intercept repeated values in an array

Postby Silvio.Falconi » Tue Oct 25, 2022 9:14 am

Now I make another test But I believe it is not correct

Code: Select all  Expand view

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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7034
Joined: Thu Oct 18, 2012 7:17 pm

Re: intercept repeated values in an array

Postby cmsoft » Tue Oct 25, 2022 10:01 am

Silvio, y crear un nuevo arreglo no?
Code: Select all  Expand view
#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
User avatar
cmsoft
 
Posts: 1285
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: intercept repeated values in an array

Postby Silvio.Falconi » Wed Oct 26, 2022 8:04 am

cmsoft wrote:Silvio, y crear un nuevo arreglo no?
Code: Select all  Expand view
#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: Select all  Expand view
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: Select all  Expand view
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: Select all  Expand view
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: Select all  Expand view
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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7034
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 44 guests