Math::...rnating(3pm)
๐ซ Math::PlanePath::DiagonalsAlternating ๐ซ
okay bestie, gather round, because today we're talking about Math::PlanePath::DiagonalsAlternating โ a lil module from the User Contributed Perl Documentation corner of the world, and it is lowkey iconic. it draws points in diagonal stripes, but the stripes alternate direction like they're doing a little catwalk walk. we're obsessed. ๐
โจ NAME โจ
Math::PlanePath::DiagonalsAlternating โ points in diagonal stripes of alternating directions ๐
๐ธ SYNOPSIS ๐ธ
use Math::PlanePath::DiagonalsAlternating;
my $path = Math::PlanePath::DiagonalsAlternating->new;
my ($x, $y) = $path->n_to_xy (123);
that's it. that's the whole vibe. you import it, you make a path, you ask it for coordinates. slay. โจ
๐ฆ DESCRIPTION ๐ฆ
so this path follows successive diagonals, going from the Y axis down to the X axis, and then back up again. like a little zigzag. no cap, it's giving escalator that can't decide which way it's going:
5 | 16
| |\
4 | 15 17
| \ \
3 | 7 14 18
| |\ \ \
2 | 6 8 13 19 ...
| \ \ \ \ \
1 | 2 5 9 12 20 23
| |\ \ \ \ \ \
Y=0 | 1 3-- 4 10--11 21--22
+----------------------------
X=0 1 2 3 4 5 6
the triangular numbers 1, 3, 6, 10, etc โ that's k*(k+1)/2 bestie, write it down โ are the start of each run up or down, alternating on the X axis and the Y axis. and then N=1, 6, 15, 28, etc on the Y axis (where Y is even) are the hexagonal numbers j*(2j-1). meanwhile N=3, 10, 21, 36, etc on the X axis (where X is odd) are the hexagonal numbers of the second kind, j*(2j+1). two kinds of hexagons, both serving looks. ๐
๐ข N Start ๐ข
the default is to number points starting from N=1, exactly like the diagram up there. but if you want a different start โ same pattern, just shifted โ there's an optional n_start for that. for example, to start at 0:
n_start => 0
and the picture becomes:
4 | 14
3 | 6 13
2 | 5 7 12
1 | 1 4 8 11
Y=0 | 0 2 3 9 10
+-----------------
X=0 1 2 3 4
glow up honestly. ๐
๐ FUNCTIONS ๐
there's a whole bunch of shared behaviour that every path class has โ go read "FUNCTIONS" in Math::PlanePath for that, bestie, it's the group chat everyone's in.
$path = Math::PlanePath::DiagonalsAlternating->new ()$path = Math::PlanePath::DiagonalsAlternating->new (n_start => $n)
create and return a shiny new path object. that's your main character moment right there. โจ
($x,$y) = $path->n_to_xy ($n)
hands you back the X,Y coordinates of point number $n on the path. super simple, super useful.
heads up: for $n < 1 the return is an empty list, because the path is considered to begin at 1. so don't be surprised when you get nothing back, it's not ghosting you, it's just the rules. ๐
๐งฎ FORMULAS ๐งฎ
๐ Rectangle to N Range ๐
inside each row, increasing X means increasing N. inside each column, increasing Y means increasing N. so in a rectangle, the lower left corner is your minimum N and the upper right corner is your maximum N. geometry said "I got you":
| N max
| ----------+
| | ^ |
| | | |
| | ----> |
| +----------
| N min
+-------------------
๐ OEIS ๐
the entries in Sloane's Online Encyclopedia of Integer Sequences related to this path include:
<http://oeis.org/A131179> (etc)
n_start=1
A131179 N on X axis (extra initial 0)
A128918 N on Y axis (extra initial 1)
A001844 N on X=Y diagonal
A038722 permutation N at transpose Y,X
n_start=0
A319572 X coordinate
A319573 Y coordinate
A319571 X,Y coordinates together
A003056 X+Y
A004247 X*Y
A049581 abs(X-Y)
A048147 X^2+Y^2
A004198 X bit-and Y
A003986 X bit-or Y
A003987 X bit-xor Y
A004197 min(X,Y)
A003984 max(X,Y)
A101080 HammingDist(X,Y)
A023531 dSum = dX+dY, being 1 at N=triangular+1 (and 0)
A046092 N on X=Y diagonal
A061579 permutation N at transpose Y,X
A056011 permutation N at points by Diagonals,direction=up order
A056023 permutation N at points by Diagonals,direction=down
runs alternately up and down, both are self-inverse
the coordinates like A003056 X+Y are literally the same here as in the Diagonals path, fr fr. DiagonalsAlternating transposes X,Y -> Y,X in every second diagonal, but forms like X+Y don't care โ swapping to Y+X changes nothing. it's giving "same energy, different font". ๐
๐ SEE ALSO ๐
Math::PlanePathMath::PlanePath::DiagonalsMath::PlanePath::DiagonalsOctant
๐ HOME PAGE ๐
<http://user42.tuxfamily.org/math-planepath/index.html>
๐ LICENSE ๐
Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Kevin Ryde
This file is part of Math-PlanePath.
Math-PlanePath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-PlanePath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
okay that's the legal bit and yes it's long but it MATTERS bestie, don't skip the license, that's not the move. ๐ซถ
and that's the whole page!! this one came from perl v5.32.0, dated 2021-01-23, and it lives in the Math::...rnating(3pm) manual section โ ty for coming to my ted talk, go make some diagonals, you're gonna ate ๐
โจ๐
๐ฆ where this page comes from
- debian bookworm: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- debian trixie: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- ubuntu jammy: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- ubuntu noble: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- ubuntu resolute: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- ubuntu stonking: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms