Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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}}
share|improve this question
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 '13 at 7:47
    
@kuba Perhaps it's the Anti-Infix-Police? –  cormullion Sep 14 '13 at 8:02
    
@cormullion so we do not like Infix here? :) I was not aware of that –  Kuba Sep 14 '13 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. –  kirma Sep 14 '13 at 8:31
add comment

5 Answers

up vote 14 down vote accepted
Table[Min[i, n + 1 - i], {n, 9}, {i, n}]
share|improve this answer
    
This is much more intuitive than mine! :) –  kirma Sep 14 '13 at 8:58
add comment

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}]
share|improve this answer
add comment
# + 1 - Abs@Range[-#, #] & /@ ((Range@9 - 1)/2)
share|improve this answer
add comment

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.

share|improve this answer
add comment

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}]

!!!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.