crop rotations pattern-matching algorithm