1997 Mathematica Developer Conference Programming Challenge

The problem was to create a function TreeGraphic, producing a Graphics object like this:

[Graphics:indexgr2.gif][Graphics:indexgr1.gif]
[Graphics:indexgr2.gif][Graphics:indexgr3.gif]
[Graphics:indexgr2.gif][Graphics:indexgr4.gif]

The hard part of this problem, as is very often the case with "real life" problems, was to figure out exactly what the problem is in the first place. When you start with an intuitive idea of what you want, it can be difficult to turn that idea into the kind of precise description that is necessary to write a program.

Here is one possible solution:

[Graphics:indexgr2.gif][Graphics:indexgr5.gif]

Some Submitted Pictures

Many people found (perhaps unintentionally) interesting variations on the graphic given.

[Graphics:indexgr2.gif][Graphics:indexgr6.gif]
[Graphics:indexgr2.gif][Graphics:indexgr7.gif][Graphics:indexgr2.gif][Graphics:indexgr8.gif]

[Graphics:indexgr2.gif][Graphics:indexgr9.gif]
[Graphics:indexgr2.gif][Graphics:indexgr10.gif]
[Graphics:indexgr2.gif][Graphics:indexgr11.gif]

[Graphics:indexgr2.gif][Graphics:indexgr12.gif]
[Graphics:indexgr2.gif][Graphics:indexgr13.gif]
[Graphics:indexgr2.gif][Graphics:indexgr14.gif]

[Graphics:indexgr2.gif][Graphics:indexgr15.gif]
[Graphics:indexgr2.gif][Graphics:indexgr16.gif]

[Graphics:indexgr2.gif][Graphics:indexgr17.gif]
[Graphics:indexgr2.gif][Graphics:indexgr18.gif]
[Graphics:indexgr2.gif][Graphics:indexgr19.gif]

[Graphics:indexgr2.gif][Graphics:indexgr20.gif]
[Graphics:indexgr2.gif][Graphics:indexgr21.gif]
[Graphics:indexgr2.gif][Graphics:indexgr22.gif]

[Graphics:indexgr2.gif][Graphics:indexgr23.gif]
[Graphics:indexgr2.gif][Graphics:indexgr24.gif]
[Graphics:indexgr2.gif][Graphics:indexgr25.gif]

[Graphics:indexgr2.gif][Graphics:indexgr26.gif]
[Graphics:indexgr2.gif][Graphics:indexgr27.gif]
[Graphics:indexgr2.gif][Graphics:indexgr28.gif]

[Graphics:indexgr2.gif][Graphics:indexgr29.gif]
[Graphics:indexgr2.gif][Graphics:indexgr30.gif]
[Graphics:indexgr2.gif][Graphics:indexgr31.gif]

[Graphics:indexgr2.gif][Graphics:indexgr32.gif]
[Graphics:indexgr2.gif][Graphics:indexgr33.gif]
[Graphics:indexgr2.gif][Graphics:indexgr34.gif]

[Graphics:indexgr2.gif][Graphics:indexgr35.gif]
[Graphics:indexgr2.gif][Graphics:indexgr36.gif]
[Graphics:indexgr2.gif][Graphics:indexgr37.gif]


The Winning Program


by Richard Mercer

Leaves[0,n_]:= &pgr;/2 + n*2&pgr;/3;
Leaves[k_,n_]:=
Leaves[k-1,Quotient[n,2]]+(-1)^Mod[n,2]*&pgr;/(3*2^k);
Leaves[k_]:= Table[Leaves[k,n],{n,0,3*2^k-1}];
Polar[r_,th_]:= {r Cos[th],r Sin[th]};
Pts[k_]:= Polar[k+1,#]& /@ Leaves[k];
Lines[0] = Line[{{0,0},#}]& /@ Pts[0]
Lines[k_]:=
Apply[{Line[{#1,First[#2]}],Line[{#1,Last[#2]}]}&,
Transpose[{Pts[k-1],Partition[Pts[k],2]}],{1}];
[Graphics:indexgr2.gif][Graphics:indexgr38.gif]

TreeGraphic[d_Integer]:=
Show[Graphics[Table[Lines[k],{k,0,d}],
{AspectRatio->Automatic}]];

Examples

TreeGraphic[1];
[Graphics:indexgr2.gif][Graphics:indexgr39.gif]

TreeGraphic[2];
[Graphics:indexgr2.gif][Graphics:indexgr40.gif]

TreeGraphic[3];
[Graphics:indexgr2.gif][Graphics:indexgr41.gif]