I have a long list with ca. 500K elements. The list contains about 10K different elements.
For simplicity let’s assume the list is of the following form:
list={a,c,b,a,a,a,b,c,e,f,b,a,e,e,e,a}
I would like to construct a function f[k]
which gives me the longest run(s) of at most k different elements. For example:
f[1]={{a,a,a},{e,e,e}},
f[2]={{b,a,a,a,b},{a,e,e,e,a}},
f[3]={{a,c,b,a,a,a,b,c}}
So far, I’ve just found this as the solution for k = 1
, which give the longest run of one element. Can this solution be extended?
And also I would also like to construct a function g[n,k]
which gives all runs with a length n
of at most k
different elements involved. For example:
g[3,2]={{b,a,a},{a,a,a},{a,a,b},{a,a,b},{b,b,a},{a,e,e},{e,e,e},{e,e,a}}
g[4,2]={{b,a,a,a},{a,a,a,b},{a,e,e,e},{e,e,e,a}}
How to construct a function h[n,k]
which gives all runs with a length n
involving at most k
different elements, but without being part of a longer run?
I would like to answer the question: How many runs exists of length n
or longer involving at most k
different elements, but without multiple counting sub runs.
For every element in g[n+1,k]
there are 2 elements in g[n,k]
. For example {{b,a,a,a},{a,a,a,b}}⊆g[4,2]
are sub runs of the run {b,a,a,a,b} ∈ g[5,2]
.