Math-PlanePath
view release on metacpan or search on metacpan
lib/Math/PlanePath/CellularRule190.pm view on Meta::CPAN
Nright = ((3Y+8)*Y + 4)/4 if Y even
((3Y+8)*Y + 5)/4 if Y odd
= Nleft(Y+1) - 1 ie. 1 before next Nleft
The row width Xmax-Xmin = 2*Y but with the gaps the number of visited points
in a row is less than that,
rowpoints = 3*Y/2 + 1 if Y even
3*(Y+1)/2 if Y odd
For any Y of course the Nleft to Nright difference is the number of points
in the row too
rowpoints = Nright - Nleft + 1
=cut
# even Nright - Nleft + 1
# = ((3Y+8)Y + 4)/4 - ((3Y+2)*Y + 4)/4 + 1
# = [ (3Y+8)Y + 4 - (3Y+2)*Y - 4 ]/4 + 1
# = [ (3Y+8)Y - (3Y+2)*Y ] / 4 + 1
# = (3Y+8-3Y-2)Y/4 + 1
# = 6Y/4 + 1
# = 3Y/2 + 1
# odd Nright - Nleft + 1
# = ((3Y+8)Y + 5)/4 - ((3Y+2)*Y + 3)/4 + 1
# = [ (3Y+8)Y + 5 - (3Y+2)*Y - 3 ]/4 + 1
# = [ (3Y+8)Y - (3Y+2)*Y + 2 ]/4 + 1
# = [ 6Y + 2 ]/4 + 1
# = [ 6Y + 2 + 4]/4
# = [ 6Y + 6]/4
# = 3(Y+1)/2
=head2 N Start
The default is to number points starting N=1 as shown above. An optional
C<n_start> can give a different start, in the same pattern. For example to
start at 0,
=cut
# math-image --path=CellularRule190,n_start=0 --all --output=numbers --size=75x6
=pod
n_start => 0
21 22 23 24 25 26 27 28 29 5
14 15 16 17 18 19 20 4
8 9 10 11 12 13 3
4 5 6 7 2
1 2 3 1
0 <- Y=0
-5 -4 -3 -2 -1 X=0 1 2 3 4 5
The effect is to push each N rightwards by 1, and wrapping around. So the
N=0,1,4,8,14,etc on the left were on the right of the default n_start=1.
This also has the effect of removing the +1 in the Nright formula given
above, so
Nleft = triangular(Y) + quartersquare(Y)
=head1 FUNCTIONS
See L<Math::PlanePath/FUNCTIONS> for behaviour common to all path classes.
=over 4
=item C<$path = Math::PlanePath::CellularRule190-E<gt>new ()>
=item C<$path = Math::PlanePath::CellularRule190-E<gt>new (mirror =E<gt> 1, n_start =E<gt> $n)>
Create and return a new path object.
=item C<($x,$y) = $path-E<gt>n_to_xy ($n)>
Return the X,Y coordinates of point number C<$n> on the path.
=item C<$n = $path-E<gt>xy_to_n ($x,$y)>
Return the point number for coordinates C<$x,$y>. C<$x> and C<$y> are each
rounded to the nearest integer, which has the effect of treating each cell
as a square of side 1. If C<$x,$y> is outside the pyramid or on a skipped
cell the return is C<undef>.
=item C<($n_lo, $n_hi) = $path-E<gt>rect_to_n_range ($x1,$y1, $x2,$y2)>
The returned range is exact, meaning C<$n_lo> and C<$n_hi> are the smallest
and biggest in the rectangle.
=back
=head1 OEIS
This pattern is in Sloane's Online Encyclopedia of Integer Sequences in a
couple of forms,
=over
L<http://oeis.org/A037576> (etc)
=back
A037576 whole-row used cells as bits of a bignum
A265688 and in binary
A071039 1/0 used and unused cells across rows
A118111 same
A071041 1/0 used and unused of mirrored rule 246
n_start=0
A006578 N at left of each row (X=-Y),
and at right of each row when mirrored,
being triangular+quartersquare
=head1 SEE ALSO
L<Math::PlanePath>,
L<Math::PlanePath::CellularRule>,
( run in 0.540 second using v1.01-cache-2.11-cpan-df04353d9ac )