# Turning Pascal's Triangle 90 degrees counter clockwise

I have a function that returns a list containing sub-lists that have the numbers for each row in the list. (ex.{{1},{1,1},{1,2,1}}) If I was going to represent it regularly I would use table form and then center it, but I need to show the triangle rotated 90 degrees counter clockwise. Are there any good ways to do this?

Update: I found out I could use;

TableForm[{{{1}, {1, 1}, {1, 2, 1}}},TableAlignments -> Center]

Does anyone know why this works?

• Would you know why this works @djp – dirtcrazy Mar 17 '15 at 4:49
• I would think you're using TableForm correctly, which is why it works! – djp Mar 17 '15 at 7:40

Update:

n = 5;
sa = SparseArray[CellularAutomaton[{Total, {}, 1/2}, {{1}, 0}, n]];

satr = Block[{i = 1}, Transpose[RotateRight[#, n + 1 - i++] & /@
(Riffle[#, {0}] & /@ sa) /.  0 -> ""]] ;
satr // Grid


Original post:

saF = SparseArray[CellularAutomaton[#, {{1}, 0}, #2]][#3] &;
ptF = Function[{n}, saF @@@ {{{Total, {}, 1/2}, n, "NonzeroValues"},
{{Unitize[#[[1]] + #[[3]]] &, {}, 1}, n, "NonzeroPositions"}}];

Row[Grid /@ {#, Transpose@#} &@SparseArray[Rule @@ Reverse[ptF[5]]], Spacer[10]]


Remove 0s:

Row[(Grid /@ {#, Transpose@#} &@
Normal[SparseArray[Rule @@ Reverse[ptF[5]]]] /. 0 -> ""), Spacer[10]]


Graphics:

Graphics[Thread[Text @@ ({Style[#, 24, Red, Bold] & /@ #, #2} & @@ #)],
AspectRatio -> 3/4] &[ptF[5]]


Graphics[Thread[Text @@ ({Style[#, 24, Red, Bold] & /@ #, Reverse /@ #2} & @@ #)],
AspectRatio -> 3/4] &[ptF[5]]


Graph:

Row[Table[Graph[Range[Length@#1], {}, VertexSize -> {.5, .5}, ImageSize -> 200,
(Placed[Style[#, 20, Red, Bold], Center] & /@ #1)],
VertexCoordinates -> i], {i, {#2, -#2}}] & @@ ptF[5], Spacer[50]]


Row[Table[Graph[Range[Length@#1], {}, VertexSize -> {.5, .5}, ImageSize -> 300,
(Placed[Style[#, 20, Red, Bold], Center] & /@ #1)],
VertexCoordinates -> i], {i, {Reverse/@#2, -Reverse/@#2}}] & @@ ptF[5], Spacer[50]]


rows = 5;

Rotate[Column[
StringJoin /@
Map[" " <> ToString[#] <> " " &,
NestList[ListConvolve[{1, 1}, #, {1, -1}, 0] &, {1}, rows], {2}],
Center], Pi/2]


Cleaner:

Row[Map[TableForm[#, TableSpacing -> 2] &,
NestList[ListConvolve[{1, 1}, #, {1, -1}, 0] &, {1}, rows]], " "]

• Cool solution +1! – mgamer Mar 14 '15 at 11:02

Here's a Graphics approach to layout:

pascal = With[{n0 = 5},
Table[Binomial[n, k], {n, 0, n0}, {k, 0, n}]
];

With[{scale = {Sqrt[3]/2, 1}, fontsize = 0.12},
Graphics[

MapIndexed[Text[#1, scale (#2 - {0, #2[[1]]/2})] &, pascal, {2}],

BaseStyle -> {"TR", FontSize -> Scaled[fontsize]},
]


tab:={{1},{1,1},{1,2,1}}

tab1=Map[Rotate[#,-90\[Degree]]&,#,{2}]&@tab

tab2=TableForm[#,TableAlignments->Center]&@tab1 (*on this stage you can apply your alignment function to tab1*)

Rotate[#,90\[Degree]]&@tab2

pascal[depth_] :=
Module[
{},
Row[#, Spacer[2]] &@
(Column[#, Center] & /@
Table[
Take[#1[[#2]], #2] & @@ {Array[Binomial, {depth, depth}, 0], i},
{i, 1, depth}
]
)
]

pascal[7]