Detecting Patterns in an array?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Detecting Patterns in an array?

  1. #1
    Join Date
    Oct 2011
    Posts
    3

    Detecting Patterns in an array?

    Hi, whilst im faily new to c# development I am a fulltime PHP developer but I suppose neither of which matter really for this question.

    What I have is an array with a size of 40 and what im doing is reading data from a source (irrelivent) every second and detecting "something" which I then set specific index's in the array from 0 to 1.

    So majority of the time the array will be zeros:

    0,0,0,0....0,0

    But I then might have 0,0,0,1,1,1,0,0,0,1,1,1,1,1,0,0...00 So as you can see I have 3 x 1's and then 5 x 1's and what I want to do is somehow detect the 1's and there positions but only if there are 2 or more 1's together? So in the above example i would detect that there was 3 x 1's and 5 x 1's and there positions?

    Is there an easy way of doing this?

    Thanks
    Andy

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,999

    Re: Detecting Patterns in an array?

    I'd remove every OTHER 0, then look for the 1's. Then, you'd have 0,1,0,1,1,1,0,1,0...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center