Math::...rnating(3pm)

๐Ÿ“ฆ
version 129 ยท 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿซถ Math::...rnating(3pm) ๐Ÿซถ

hiii bestie ๐Ÿ’– this is the Math::...rnating(3pm) page (User Contributed Perl Documentation, no biggie) and it's about Math::PlanePath::StaircaseAlternating. stairs. diagonals. up. down. we love to see it. grab a snack ๐Ÿ“


โœจ NAME โœจ

Math::PlanePath::StaircaseAlternating โ€” stair-step diagonals up and down ๐Ÿ’ƒ that's it, that's the name, periodt.

๐ŸŽ€ SYNOPSIS ๐ŸŽ€

use Math::PlanePath::StaircaseAlternating;
my $path = Math::PlanePath::StaircaseAlternating->new;
my ($x, $y) = $path->n_to_xy (123);

๐ŸŒˆ DESCRIPTION ๐ŸŒˆ

okay so picture this: this path makes a staircase pattern that goes up from the Y axis, all the way down to the X, and then back up again. escalator energy honestly ๐Ÿ›—โœจ

10       46
          |
 9       47--48
              |
 8       45  49--50
          |       |
 7       44--43  51--52
              |       |
 6       16  42--41  53--54
          |       |       |
 5       17--18  40--39  55--...
              |       |
 4       15  19--20  38--37
          |       |       |
 3       14--13  21--22  36--35
              |       |       |
 2        2  12--11  23--24  34--33
          |       |       |       |
 1        3-- 4  10-- 9  25--26  32--31
              |       |       |       |
Y=0 ->    1   5-- 6   8-- 7  27--28  30--29

          ^
         X=0  1   2   3   4   5   6   7   8

๐Ÿ”ฒ Square Ends ๐Ÿ”ฒ

the end_type => "square" option switches the path up like this โ€” it omits one point at each end so the joins square up all neat and tidy:

 9       42--43
          |   |
 8       41  44--45
          |       |
 7       40--39  46--47
              |       |
 6        .  38--37  48--49
                  |       |
 5       14--15  36--35  50--...
          |   |       |
 4       13  16--17  34--33
          |       |       |
 3       12--11  18--19  32--31
              |       |       |
 2        .  10-- 9  20--21  30--29
                  |       |       |
 1        2-- 3   8-- 7  22--23  28--27
          |   |       |       |       |
Y=0 ->    1   4-- 5-- 6   .  24--25--26

          ^
         X=0  1   2   3   4   5   6   7   8

so the effect? each diagonal gets shortened by a constant 1 every single time ๐Ÿซข and the lengths of each diagonal still grow by +4 each time (or by +16 up and back). the math is mathing ๐Ÿ’…

๐Ÿ”ข N Start ๐Ÿ”ข

the default is to number points starting at N=1, exactly like the pic above bestie. there's also an optional n_start that gives you a different start, same pattern, different vibe. for example, to start at 0:

n_start => 0                  n_start => 0, end_type=>"square"

46 47                            41 42
44 48 49                         40 43 44
43 42 50 51                      39 38 45 46
15 41 40 52 53                      37 36 47 48
16 17 39 38 ...                  13 14 35 34 ...
14 18 19 37 36                   12 15 16 33 32
13 12 20 21 35 34                11 10 17 18 31 30
 1 11 10 22 23 33 32                 9  8 19 20 29 28
 2  3  9  8 24 25 31 30           1  2  7  6 21 22 27 26
 0  4  5  7  6 26 27 29 28        0  3  4  5    23 24 25

๐Ÿ’– FUNCTIONS ๐Ÿ’–

peep "FUNCTIONS" in Math::PlanePath for the behaviour that's common to every path class, iykyk.

  • $path = Math::PlanePath::StaircaseAlternating->new ()
  • $path = Math::PlanePath::StaircaseAlternating->new (end_type => $str, n_start => $n) โ€” creates and returns a brand new path object โœจ the end_type choices are:
    "jump"        (the default)
    "square"
  • ($x,$y) = $path->n_to_xy ($n) โ€” hands you back the X,Y coordinates of point number $n on the path. no gatekeeping ๐Ÿซถ

๐Ÿงฎ OEIS ๐Ÿงฎ

entries in Sloane's Online Encyclopedia of Integer Sequences related to this path include:

<http://oeis.org/A084849> (etc)

end_type=jump, n_start=1  (the defaults)
  A084849    N on diagonal X=Y
end_type=jump, n_start=0
  A014105    N on diagonal X=Y, second hexagonal numbers
end_type=jump, n_start=2
  A096376    N on diagonal X=Y

end_type=square, n_start=1
  A058331    N on diagonal X=Y, 2*squares+1
end_type=square, n_start=0
  A001105    N on diagonal X=Y, 2*squares

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

  • Math::PlanePath
  • Math::PlanePath::Staircase
  • Math::PlanePath::DiagonalsAlternating

๐Ÿ  HOME PAGE ๐Ÿ 

<http://user42.tuxfamily.org/math-planepath/index.html>

๐Ÿ“œ LICENSE ๐Ÿ“œ

Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Kevin Ryde

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/>.


and that's the whole page, babe ๐Ÿ’œ this was perl v5.32.0, dated 2021-01-23, and it's Math::...rnating(3pm) โ€” now go build a staircase, you're the main character ๐Ÿ‘‘โœจ๐ŸŒธ