# Better way to make a certain list with palindromic sublists

Here is my code, which works, but seems a little too long, I think might be a more refined version.

Range[Ceiling[#/2]] ~ Join ~
If[OddQ[#], Rest, Identity] @ Reverse @ Range[Ceiling[#/2]] & /@ Range[9]

Range[Ceiling[#/2]] ~ Join ~ Range[Floor[#/2], 1, -1] & /@ Range[9]

{{1}, {1, 1}, {1, 2, 1}, {1, 2, 2, 1}, {1, 2, 3, 2, 1}, {1, 2, 3, 3,  2, 1},
{1, 2, 3, 4, 3, 2, 1}, {1, 2, 3, 4, 4, 3, 2, 1}, {1, 2, 3, 4, 5, 4, 3, 2, 1}}

• Can I ask downvoters about the reason? I do not claim they have no reason, I just can't see any now.
– Kuba
Sep 14, 2013 at 7:47
• @kuba Perhaps it's the Anti-Infix-Police? Sep 14, 2013 at 8:02
• @cormullion so we do not like Infix here? :) I was not aware of that
– Kuba
Sep 14, 2013 at 8:05
• Talking of infix ~Join~ - innumerable times I've pondered why Mathematica doesn't have a better infix shorthand for it. There's <> for StringJoin, after all. Sep 14, 2013 at 8:31

Table[Min[i, n + 1 - i], {n, 9}, {i, n}]

• This is much more intuitive than mine! :) Sep 14, 2013 at 8:58

The question is in my opinion more about math than Mathematica and so is my answer (unless the goal is to create these lists through specific constructs), but here it is nonetheless:

Table[(1 + x - Abs[1 - 2 n + x]) / 2, {x, 9}, {n, x}]


Although I think Ray Koopman's method is the way to go, I cannot pass on pointing out the similarity to TriangleWave, therefore:

Table[n/2 TriangleWave[i/2/n], {n, 2, 10}, {i, n - 1}] // Simplify

{{1}, {1, 1}, {1, 2, 1}, {1, 2, 2, 1}, {1, 2, 3, 2, 1}, {1, 2, 3, 3, 2, 1},
{1, 2, 3, 4, 3, 2, 1}, {1, 2, 3, 4, 4, 3, 2, 1}, {1, 2, 3, 4, 5, 4, 3, 2, 1}}


Simplify is needed because TriangleWave does not fully evaluate in some cases without it.

# + 1 - Abs@Range[-#, #] & /@ ((Range@9 - 1)/2)


Just for the heck of it, a recursive solution:

f[1] = {1};
f[n_] := f[n] = With[{list = f[n - 1]},
If[EvenQ[n - 1],
Insert[list, 1 + list[[(n - 1)/2]], (n + 1)/2],
Insert[list, list[[n/2]], 1 + n/2]]
];

Table[f[k], {k, 1, 10}]


!!!