Pachrant 0 Newbie Poster

This is my own humble contribution to your problem. If it is better or worser I don't know, but it might give you some ideas.

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //this only works with numbers in succession
            int[] range = new int[7] { 0, 2, 1, 1, 1, 4, 5 };
            //int[] range = new int[7] { 0, 2, 2, 1, 1, 1, 1 }; 
            
            List<int> tmp = new List<int>();
            tmp.AddRange( range );

            foreach (int i in tmp)
            {
                //can be optimised: if 3 found, jump 3 further in list
                Console.WriteLine(i);
                int first = tmp.IndexOf(i);
                int last = tmp.LastIndexOf(i);
                int t = last - first + 1;
                if ( t >= 3 )
                    Console.WriteLine("--> {0} appears {1} times in the list.", i, t);
            }
            Console.ReadKey();
        }
    }
}

Another possibility might be you construct a binary tree.
Loop through your input.
If the number is not in the tree insert it.
If the number is already in the tree augment a count variable you keep with the number.
Afterwards, traverse the tree and note which numbers have a count >=3.

I'm not so good at that but look here for info : http://msdn.microsoft.com/en-us/library/ms379572.aspx

Succes!

Ok, I dont compile your code, but I think that it cant handle more same paterns in array like:
int[] range = new int[7] { 1, 1 1, 0, 1, 1, 1 };
or maybe can produce mistakes like:
int[] range = …

Pachrant 0 Newbie Poster

A List or an Array has a FindAll method. This is what I should use as a start. Start coding!
Any problems with it, come back here.

Im using this:
Its not best solution, but it works.
Thank for your time.

public Dictionary<int,int> FindSeries(string[] v_Patern , string[] v_Array)
        {
            Dictionary<int,int> result=new Dictionary<int,int>();

            string s= String.Join("",  v_Array,0,v_Array.Length);

            string p= String.Join("",  v_Patern,0,v_Patern.Length);
            string patern="";
            for (int l = 0; l < v_Array.Length; l++)
                patern += p;
            for (int i = 0; i < v_Array.Length; i += v_Patern.Length)
            {
                patern = patern.Substring(0, patern.Length - p.Length);
                if (patern.Length >= 3) // more than 3 occurrances of patern required
                {
                    while (s.IndexOf(patern) != -1)
                    {
                        bool b = true;
                        foreach (KeyValuePair<int, int> d in result)
                            if ((s.IndexOf(patern) > d.Key && s.IndexOf(patern) < d.Key + d.Value))
                                b = false;
                        if (b)
                        {
                            result.Add(s.IndexOf(patern), patern.Length);
                            break;
                        }
                    }
                }
            }
            return result; //return value key: index, value number of occurrances
        }

but if anyone find, or know a better solution Im alble to rewrite it

Pachrant 0 Newbie Poster

I will, dont worry, but I hoped that it will be a better (easier) solution, how to do that.
IE cast it to the some collection and use any method or as I mention before cast it to the strig and use regex or any function like contains()...
I´m realy disappointed about it.... Still hope that anyone direct me at the right way. Thx for any advice...

Pachrant 0 Newbie Poster

I want to find a series of chars in a string, but I dont know, how to write a regex, please help.
I have to find in a string occurrances of 3 or more same chars in a row.
IE:
"4123478888"// four same chars starts at inex 6

or

"321222468"//3 same chars start at index 3

or
"55555698752111"5same chars start at index 0 3 same chars start at index 11

and so on...

please help.I appreciate of any sugestion. Thx.

Pachrant 0 Newbie Poster

To make it more clear. (or otherwise >) ) :
I have 2 dimensional array (12 rows and 12 cols) filled with numbers {1,2,3,4,5} and what I have to do is remove from it (make it 0) occurrences of 3 and more (max 12) same numbers in a row. I have to do that in horizontal and vertical way.
hope this helps undestand. Any sugestions?

Pachrant 0 Newbie Poster

What have you tried so far?
What code do you already have and what are the problems you have with it?

So, I tried to iterate thru the array using for loop and at each iteration remember previous number and count how many numbers are same.

But I gave up before end becouse it not seemd to me as good method.

I hope there is more sophisticated method to do that. Maybe allready written function... Dont Know.

I was thinking about cast the array to string and use regex ... but Im not sure Im able to define a patern and use it.

Pachrant 0 Newbie Poster

Hello everybody...
Can anyone help me with this?:
I want to check out an array, if there is any number which is 3, or more times in a row.

IE:
int[] tmp= new int[7]{0,2,1,1,1,4,5}; // yes 3 duplicities starts at index 2

int[] tmp= new int[7]{0,2,2,1,1,1,1}; // yes 4 duplicities starts at index 3

any ideas?

Thanks for any answer.