I would like replace the following code
With[{n = 5},
Flatten[
Table[Join @@ NestList[Abs@Differences@# &, {a, b, c, d, e}, n - 1] // Evaluate,
{a, #}, {b, #}, {c, #}, {d, #}, {e, #}] &[n (n + 1)/2], n - 1]]; // AbsoluteTiming
(*{0.551032, 759375}*)
with this
With[{n = 5},
Join @@ NestList[Abs@Differences@# &, #, n - 1] & /@
Tuples[Range[n (n + 1)/2], n]]; // Timing
but the second method is much slower than the first. How can I make it fast?
n=3
orn=4
, I have to modify more about original code. $\endgroup$