numbers in array

numbers in array

Postby Silvio.Falconi » Fri Feb 26, 2016 11:35 am

I have an array

anumbers:= {1,1,1,7,1}

I want to know if: (starting from the left)

1) at least the first three numbers are the same sample -> {1,1,1,7,1}
2) at least the first four numbers are the same sample -> {1,1,1,1,9}
3) at least 5 numbers are the same sample -> {1,1,1,1,1}

and it must return me a value logic wich is true
but it is possible I can have all logic values when the numbers are {1,1,1,1,1}
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: 7048
Joined: Thu Oct 18, 2012 7:17 pm

Re: numbers in array

Postby ukoenig » Fri Feb 26, 2016 3:42 pm

Silvio,

I think the solution / calculation You are looking for ?
I tested all possible combinations
In case from left 3 equal numbers You get .T. for the array-elements
otherwise less 3 equal numbers all 5 elements are .F..
In case You need the .T. of the elements as well for 3 not completed
there is no problem. 5 times .F. just means NOT completed.
From the calculation You can build any logic You need.

ONLY test 2 is completed !!!

Image

Code: Select all  Expand view

FUNCTION TESTARRAY(aGet, aSay)
LOCAL i, m, n, x

/*
REQUESTED

I have an array
anumbers:= {1,1,1,7,1}
I want to know if: (starting from the left)

1) at least the first three numbers are the same sample -> {1,1,1,7,1}
2) at least the first four numbers are the same sample -> {1,1,1,1,9}
3) at least 5 numbers are the same sample -> {1,1,1,1,1}

and it must return me a value logic wich is true
but it is possible I can have all logic values when the numbers are {1,1,1,1,1}
*/


I := 1
FOR I := 1 TO 5
    aSay[I] := .F. // Results
NEXT

i := 1
n := aGet[1]           // first number
m := 0                  // count same numbers from left
x := n                 // number
FOR I := 1 TO 5
    IF I > 1           // count from 2. value
        x := aGet[I]
    ENDIF
    IF x = n         
        m++           // count if same number
    ELSE
        EXIT
    ENDIF
NEXT

MsgAlert( m, "same following Numbers" )
i := 1
FOR I := 1 TO 5
    IF m >= 3 .and. I <= m
        aSay[I] = .T. // equal fields are .T. only if counter >= 3
    ENDIF
NEXT

RETURN NIL
 


best regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: numbers in array

Postby Silvio.Falconi » Sat Feb 27, 2016 9:53 am

I found another symple solution
for sample to contro the 3 numbers

// for 3x
IF nNumbers[1]== nNumbers[2] .and. nNumbers[1]==nNumbers[3]
l3x:= .t.
lplinestring[z][1]:= l3x
Endif



this is the sample :
sample combination for 25 combination strings

Local aline := {{1,3,6,7,1},;
{3,1,6,1,9},;
{9,3,1,7,9}}

Image
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: 7048
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 117 guests