Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 141

 
Artyom Trishkin:

Friends, I've been working too hard...

Here's the question: There is an array of, say, four numbers. We need to find out the number of equal numbers in the array.

1,2,3,4 - no identical numbers
1,1,2,3 - two same numbers
1,1,2,2 - also two identical numbers.
1,2,1,2 - there are two identical.
1,1,1,2 - three alike
1,1,1,1,1 - four of them are the same.

It doesn't seem complicated, but I can't think of anything...

HOW?

Arrange the array and do a comparison with the current and past values, if matched, then counted - or I do not understand the question.
 
Artyom Trishkin:

Friends, I've been working too hard...

Here's the question: There is an array of, say, four numbers. We need to find out the number of equal numbers in the array.

1,2,3,4 - no identical numbers
1,1,2,3 - two same numbers.
1,1,2,2 - also two identical numbers.
1,2,1,2 - there are two similar ones
1,1,1,2 - three alike
1,1,1,1,1 - four of them are the same.

It doesn't seem complicated, but I can't think of anything...

HOW?

int Res = 1;  

if (ArraySort(Array))
{    
  int Tmp = 1;
  
  for (int i = ArraySize(Array) - 1; i > 0; i--)
  {
    if (Array[i - 1] != Array[i])
    {
      if (Tmp > Res)
        Res = Tmp;
      
      Tmp = 0;
    }
      
    Tmp++;
  }
}
Didn't check it. The result is in Res.
 
fxsaber:
int Res = 1;  

if (ArraySort(Array))
{    
  int Tmp = 1;
  
  for (int i = ArraySize(Array) - 1; i > 0; i--)
  {
    if (Array[i - 1] != Array[i])
    {
      if (Tmp > Res)
        Res = Tmp;
      
      Tmp = 0;
    }
      
    Tmp++;
  }
}
Didn't check it. Res result in Res.

Yeah, I'll have a look. Thank you. I get the idea

Just got my horn in the simple, doing the complex ....

 
-Aleks-:

Arrange the array and do a comparison with the current value and the past value, if matched, then counted - or I don't understand the question.
Thanks. Just a little bit wrong - there may be several matching but different numbers between them.
 
Artyom Trishkin:
Thanks. Just a bit wrong - there may be several matching but different numbers between them.

definitely worked out :-)

 
Artyom Trishkin:
Thanks. Just a bit wrong - there may be several matching but different numbers.

The problem needs to be defined more clearly.

1) A number is given as input and you want to output how many matches there are for that number in the array.

2) Or do you want to output all the numbers that are duplicated in the array?

 
. ... Rick D. ... .:

You need a clearer definition of the problem.

1) A number is given as input and you want to output how many matches there are for that number in the array.

2) Or do you want to output all the numbers that are duplicated in the array?

Neither of them.

There are four known unknown numbers. You need to find the number of duplicate numbers as in the example in my first post.

 
Maxim Kuznetsov:

definitely worked out :-)

Yeah, well... Worked out :))

I don't know what to call these numbers: 1,1 2,2 ... or 1,2,1,2 - here the number (result) is 2

repeated (1,1)... but different(1,1,2,2) ... - and here the number (result) is 2

And how do I call it correctly - I don't know - I'm not a client, though

ZS. By the way - repetitive - that's me for nothing... Otherwise you might think that "going in a row"... That's not necessary.

Just the number of matching numbers. Although that might not be the right way to put it either... yes... it's a hard life for the customer...

 
Artyom Trishkin:

I don't know what to call it - I'm not a customer, though.

Maximum number of identical values in a sequence?
 
Alexey Kozitsyn:
The maximum number of identical values in a sequence?

Nope :)))

1,1,1,2,3,3,2,1,4,4,5

is the number of numbers of the same colour.