Mathematica 3.0 code to create Catalan polygon diagrams (sorry, but
I wrote it to teach myself how to use the new ReplaceList function,
not to be readable):
(* The corners of an n-gon... *)
poly[n_] := Table[{Cos[t], Sin[t]}, {t, 0, 1.999 Pi, 2 Pi/n}]
(* A test to see if two indexed corners can be opposites in an n-gon,
in other words a test that they're not adjacent... *)
test[{i_, j_}, n_] := 1 < Mod[Abs[i - j], n] < n - 1;
(* All the possible pairs of opposite corners for an n-gon. *)
opposites[n_]:=
Select[Union[
Sort /@ Flatten[Outer[List, Range[n], Range[n]], 1]],
test[#, n]&];
(* A silly trick to get patterns of the form
{___,a,___,b,___} -> {a, b}. *)
myrule[n_] :=
With[{patts = Table[Unique["e"], {n}]},
Rule[Prepend[
Flatten[Map[{Pattern[#, Blank[]], BlankNullSequence[]}&, patts]],
BlankNullSequence[]], patts]];
(* For example...
myrule[4]
{___,e1_,___,e2_,___,e3_,___,e4_,___} -> {e1,e2,e3,e4} *)
(* A test to see if two diagonals of a polygon intersect... *)
test2[{___,{x_,y_},___,{a_,b_},___} /; (x<a<y<b || a<x<b<y)] := True;
(* Put it all together... Once you understand this, you'll be as bad at
programming as I am. *)
showCatalan[n_]:=
Module[{bg, corners, thelines, poly = N@poly[n]},
bg = Line[Append[poly, First[poly]]];
>
Transfer interrupted!