On 11/29/2017 11:40 PM, Roger Hui wrote:
> 2.5 Cantor Set
>
> Write a function to compute the Cantor set of order n, n>:0.
>
>     Cantor 0
> 1
>     Cantor 1
> 1 0 1
>     Cantor 2
> 1 0 1 0 0 0 1 0 1
>     Cantor 3
> 1 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 1
>

In Mathematica:

cantor[n_] := If[n == 0, {1},
cantor[n - 1] /. {0 -> Sequence[0, 0, 0], 1 -> Sequence[1, 0, 1]}]

I doubt J could do substantially better, but I'll leave that to you experts.

> 2.6 Sierpinski Carpet
>
> Write a function to compute the Sierpinski Carpet of order n, n>:0.
>
>     SC 0
> 1
>     SC 1
> 1 1 1
> 1 0 1
> 1 1 1
>     SC 2
> 1 1 1 1 1 1 1 1 1
> 1 0 1 1 0 1 1 0 1
> 1 1 1 1 1 1 1 1 1
> 1 1 1 0 0 0 1 1 1
> 1 0 1 0 0 0 1 0 1
> 1 1 1 0 0 0 1 1 1
> 1 1 1 1 1 1 1 1 1
> 1 0 1 1 0 1 1 0 1
> 1 1 1 1 1 1 1 1 1
I believe Mathematica has no built in tiling function, so I wrote one.

tile[m_] := Join @@ ((Join @@@ #) & /@ (Transpose /@ m));

hole = {{1, 1, 1}, {1, 0, 1}, {1, 1, 1}};
zeros = Table[0, {3}, {3}];

sierpinski[n_] := If[n == 0, {{1}},
   tile[sierpinski[n - 1] /. {1 -> hole, 0 -> zeros}]]


The tiling utilities in J are very nice.



Could give a reference for the extend H algorithm?  I get the idea, but 
I'm a little unclear about the details.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to