FindRepeat

FindRepeat[list]

finds the minimal sublist that repeats to give list.

FindRepeat[list,n]

requires that the sublist is repeated at least n times in list.

FindRepeat[list,{n1,n2,}]

requires ni repeats at level i in list.

FindRepeat["string"]

finds the minimal substring that repeats to give string.

FindRepeat["string",n]

requires that the substring is repeated at least n times.

Details and Options

  • FindRepeat[expr] gives expr if no repeat is found.
  • FindRepeat[list,2] gives {} if no repeat is found. FindRepeat["string",2] gives "".
  • FindRepeat[expr] allows incomplete repeats at the end of expr.
  • FindRepeat[expr,n] requires at least n complete repeats.
  • FindRepeat[list] is equivalent to FindRepeat[list,Table[1,ArrayDepth[list]]].
  • The length of the list {n1,n2,} must be less than or equal to ArrayDepth[list].
  • FindRepeat works on SparseArray and StructuredArray objects.
  • FindRepeat works on associations, effectively ignoring their keys and returning an association with keys corresponding to the first occurrence of the repeated block.
  • FindRepeat[list,{n1,n2,,nk},SameTest->test] applies test to each pair of elements at level k to determine whether they should be considered the same.

Examples

open allclose all

Basic Examples  (4)

Find the sublist that repeats to form a list:

In[1]:=
Click for copyable input
Out[1]=

The last sublist does not need to be complete:

In[2]:=
Click for copyable input
Out[2]=

Find a sublist that repeats at least four times:

In[1]:=
Click for copyable input
Out[1]=

An empty list is returned if no sublist satisfies the condition:

In[2]:=
Click for copyable input
Out[2]=

Find the repeated block of a matrix:

In[1]:=
Click for copyable input
Out[1]//MatrixForm=
In[2]:=
Click for copyable input
Out[2]//MatrixForm=

Find the repeated substring of a string:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Scope  (10)

Options  (4)

Applications  (6)

Properties & Relations  (5)

See Also

FindTransientRepeat  Fourier  FindSequenceFunction  FunctionPeriod  Repeated  StringRepeat  Table

Introduced in 2017
(11.2)