@Victor_G perfect.
I wrote this JSL and was unhappy with the answer it provides that includes overlapping duplicates.
// build a sample table
dtElements = New Table( "elements", New Column( "element", Numeric, setvalues( J( 20, 1, Random Integer( 1, 3 ) ) ) ) );
nr = N Rows( dtElements );
// build key table
maxKeyLen = 12; // too big will be slow, too small will miss something
dtKeys = New Table( "keys", addrows( nr ), New Column( "key", expression, Set Display Width( 239 ) ) );
For( irow = 1, irow <= nr, irow += 1,
maxrow = Min( nr, irow + maxKeyLen );
dtKeys:key[irow] = dtElements:element[irow :: maxrow];
);
// sort key table to put similar together
dtKeys << Sort( By( :key ), Replace Table, Order( Ascending ) );
// get the match length of adjacent rows
// ===========================================
// this code finds two runs of 1,1,1 in 1,1,1,1 <<<<<<<<<< IMPORTANT <<<<<<<<<<<
// ===========================================
dtKeys << New Column( "matchLength" );
For( irow = 2, irow <= nr, irow += 1,
a = dtKeys:key[irow];
b = dtKeys:key[irow - 1];
result = Min( N Items( a ), N Items( b ) );
For Each( {{aa, bb}, i}, across( a, b, Count( "Shortest" ) ),
If( aa != bb,
result = i - 1;
Break();
)
);
dtKeys:matchLength[irow] = result;
);
dtKeys << Sort( By( :matchLength ), Replace Table, Order( Descending ) );
Show( dtKeys:key[1][1 :: dtKeys:matchLength[1]] );
The JSL uses an Expression column, ForEach( Across, Count ) and handles both numeric and character input. But I don't think it will quite do what @ruskicar wants.
The idea is to create a new column of values built from the next N rows. Sorting that column puts runs of similar starting patterns adjacent.
Craige