Cantor =: 3 : ', 1 0 1 */^:y ,1'
SC     =: 3 : '(3 3$4>i.5) ,./^:2@(*/)^:y ,.1'

Recursive solutions using the Mathematica ReplaceAll (/.) idea are also
possible, using indexing ({):

Cantor1=: 3 : 'if. 0=y do. ,1 else. ,(Cantor1 y-1){0,:1 0 1 end.'
SC1    =: 3 : 'if. 0=y do. ,.1 else. ,./^:2 (SC1 y-1){0,:3 3$4>i.5 end.'

Checking that they give the same results:

   (Cantor -: Cantor1)"0 i.8
1 1 1 1 1 1 1 1
   (SC -: SC1)"0 i.8
1 1 1 1 1 1 1 1

I claim the examples in my message unambiguously specify the extended H
problem.  More details (and solutions) can be found in
http://code.jsoftware.com/wiki/Essays/Extended_H




On Thu, Nov 30, 2017 at 9:33 PM, Dabrowski, Andrew John <
[email protected]> wrote:

> 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to