Another iterator:
(slower and fatter)

,@(,0,:])^:(]`(1"_))

... and there's an interesting(?) relation with OEIS sequence A005836.


Op 01-12-17 om 12:53 schreef Arie Groeneveld:
How about

   c0=:,@((1 0 1 */])^:(]`(1"_)))
   5 ts ' c0 18'
0.123306 6.71091e8

compared to:

   c01=:,@((1 0 1 */])^:(]`(1:)))
   5 ts ' c01 18'
1.23536 5.36871e9

and

   5 ts ' c1 18'
0.0948998 6.03985e8

   (c0-:c1)18
1


Op 01-12-17 om 10:32 schreef Marshall Lochbaum:
And for computing large Cantor sets really fast, you can use a recursive
method:

    c0 =. 3 :', */&1 0 1^:y 1'
    c1 =. 3 :', (*/~(3^y-2^l)&{.) , */~^:(l=.<.2^.y) 1 0 1'
    (c0 -: c1) 18
1
    10 (6!:2) 'c0 18'
1.22999
    10 (6!:2) 'c1 18'
0.0728543

The J solution makes it easy to figure this out, because */ is
associative. With Mathematica, it's completely opaque.

Marshall

On Thu, Nov 30, 2017 at 10:20:43PM -0800, Roger Hui wrote:
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
----------------------------------------------------------------------
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