3
$\begingroup$

SequenceCases is not performing as expected. Here's an example to illustrate: Find all the triples where the pair {hi, mid} precedes {hi,lo} and {hi,lo} precedes {mid,lo} in an ordered list, where hi > mid > lo.

list = {{6, 3}, {6, 1}, {6, 2}, {3, 1}, {3, 2}};
SequenceCases[list, 
              {{hi_, mid_}, ___, 
               {aa_, lo_},  ___, 
               {bb_, cc_}} /; 
               lo < mid < hi && 
               aa == hi && 
               bb == mid && 
               cc == lo -> {{hi, mid}, {mid, lo}}, Overlaps -> True]

Inspection identifies two triples:

  1. {6,3} precedes {6,2} which precedes {3,2} and
  2. {6,3} precedes {6,1} which precedes {3,1}

But SequenceCases only returns the first one: {{{6,3},{3,2}}}.

I was careful to put the BlankNullSequence "___" between the Rules. Am I missing something?

$\endgroup$

1 Answer 1

2
$\begingroup$

Yes, I am missing something: Overlaps->All is the appropriate option.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.