Consider the following:
data={a,b,c,d};
res={{a,b,c,d},{b,c,d,e},{c,d,e,f},{d,e,f,g}};
The idea is to define a function MyFunction
which will return res
when applied on data
. Please note that for every recursive step the function will delete the first element of a 4-tuple and append one element to this tuple.
I had the following idea which worked but maybe somebody has a much shorter version:
ListBuilder[data_] := Module[
{data1 = data, data2, data3, data30},
data2 =
Join[{data1}, {data1 /. {a_, b_, c_, d_, e_, f_, g_, h_} :>
Flatten@{b, c, d, e, f, g, h,
Round@RandomVariate[NormalDistribution[1000, 0.1*1000], 1]}}];
data3 =
Join[data2, {data2[[-1]] /. {a_, b_, c_, d_, e_, f_, g_, h_} :>
Flatten@{b, c, d, e, f, g, h,
Round@RandomVariate[NormalDistribution[1000, 0.1*1000], 1]}}];
While[Length@data3 < 8,
data3 = Join[
data3, {data3[[-1]] /. {a_, b_, c_, d_, e_, f_, g_, h_} :>
Flatten@{b, c, d, e, f, g, h,
Round@RandomVariate[NormalDistribution[1000, 0.1*1000],
1]}}];
data3];
data3
]
SeedRandom[32452345]
NumData = Round@RandomVariate[NormalDistribution[1000, 0.1*1000], 8]
NumRes=ListBuilder@NumData
EDIT
It would also be interesting to allow list building with more than one argument (e.g. answer by YvesKlett.)
Does anyone have an idea?