Best strategy for finding a pattern in a sequence of integers

Slaunger Slaunger at gmail.com
Fri Nov 21 19:18:52 EST 2008


On 21 Nov., 23:36, Mensanator <mensana... at aol.com> wrote:
> Your rules appear to be incomplete and inconsistent.
OK. Let me try to clarify then...

> > 3. Pattern A only consists of the numbers 0, 3, and 9. 3, 3 is always
> > followed by 0
>
> But does a 3 always follow a 3? Can you have 3, 0, 3, 0?
> Can 0's occur without 3's, such as 0, 0, 0?
Yes, 3s always comes in pairs. So, 3, 0, 3, 0 is not allowed.
And of the numbers 0, 3, and 9; 0 will always be the first after the
pair of 3s

>
> > 4. Pattern B only consists of the numbers 1, 6, and 10. 6, 6, is
> > always followed by 1
> > 5. There may be other numbers interspersed within the sequence, but
> > they can be ignored
>
> So, I can have 3, 3, 0, 7, 3, 3, 0?
Yes, there is a point I did not mention propery in my first
description:
The number 7 for instance could appear in that position, but it would
not be repetitive;
as a matter of fact these other numbers can be filtered away before
looking for the pattern,
so let us just forgot about those.

>
> What if the 7 occurs after the pair of 3's? Is the number following
> the 7 forced to be 0, i.e., is 3, 3, 7, 3, 3, 0 legal?
No, it would have to be 3, 3, 0, 7, 3, 3, 0, it is sequeezed in - but
as mentioned they can be prefiltered out of the problem
>
> > 7. The beginning of a pattern is marked by the transition from oner
> > pattern to the other.
>
> Can there be an ignored number between the patterns? Is
> 9,3,3,0,7,10,6,6,1
> legal? If NO, you violate Rule 5. If YES, you violate the second Rule
> 7.
Yes you are right. This complication is again eliminated by
prefiltering "other" numbers out

-- Slaunger



More information about the Python-list mailing list