Adaptation of a linear system to a finite set of patterns occurring in an arbitrarily varying order