> Now why steps 10-13 result in the next row of a sierpinski triangle, I
> don't know, I guess it has to do with generating a Pascal triangle.

It's not that important for learning J, but it gives a hint why the
seemingly confusing `72#:~8#2` was used. `bm{~3#.\row` maps three consecutive
bits to base 10, which then indexes into 0 1 0 0 1 0 0 0. It helps
to visualize this without the conversion/indexing:

  (#:i.8);(,.72#:~8#2)
0 0 0|0
0 0 1|1
0 1 0|0
0 1 1|0
1 0 0|1
1 0 1|0
1 1 0|0
1 1 1|0

There are 8 possibilites, thus we need a bit map that is 8 bits long (8#2).
To understand why this generates the Sieprinski triangle, it helps to
ignore rows where two consecutive 1s exist, as they are not possible in this
visualization:
0 0 0|0
0 0 1|1
0 1 0|0
1 0 0|1
1 0 1|0

We can see that the middle column isn't needed anymore to determine the
output, so lets ignore it, too:
0 0|0
0 1|1
1 0|1
1 1|0

And this just says that a point is the XOR of its two parents.  So this
corresponds to a pascal triangle with XORing the elements instead of
adding them, which is a neat way to keep track of the parities inside
Pascal's without calculating the numbers.

50% of the complexity of that line stems from the padding between cells 
so the top is in the middle, the other 50% making XORing more complicated
than it needs to be: (3 ({. ~: {:)\ 0,],0:). :-)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to