Math::N...angular(3)

πŸ“¦
version 75 Β· 2 versions
, in fedora 43

✨ Math::N...angular(3) ✨

okay so bestie β€” this is a page from the User Contributed Perl Documentation collection, and it's all about Math::NumSeq::Triangular, aka triangular numbers πŸŽ€. Buckle up, it's lowkey adorable and highkey useful.


πŸ’– NAME πŸ’–

Math::NumSeq::Triangular β€” triangular numbers. That's it, that's the vibe πŸ¦‹


🌸 SYNOPSIS 🌸

use Math::NumSeq::Triangular;
my $seq = Math::NumSeq::Triangular->new;
my ($i, $value) = $seq->next;

three lines and you're in, no cap πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So the triangular numbers are literally i*(i+1)/2, and they go like:

0, 1, 3, 6, 10, 15, 21, 28, ...
starting i=0

The way that these numbers are just how many points fit in an equilateral triangle of side i?? Obsessed. Look:

   *      i=1  1

   *      i=2  3
  * *

   *
  * *     i=3  6
 * * *

   *
  * *     i=4  10
 * * *
* * * *

fr fr, it's giving geometry and I ate πŸ“

And here's the cute part: from a given i, the next value is formed by adding i+1 β€” that's a new row of that length plopped on the bottom of the triangle. Stacking rows like a little pointy staircase πŸ‘‘βœ¨


πŸ’œ FUNCTIONS πŸ’œ

See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes. (iykyk β€” that's the family, go say hi 🫢)

  • "$seq = Math::NumSeq::Triangular->new ()" β€” creates and returns a brand new sequence object. main character energy, honestly πŸ’…

πŸ”₯ Random Access πŸ”₯

  • "$value = $seq->ith($i)" β€” hands you back "$i*($i+1)/2". yes that exact thing. no notes.
  • "$bool = $seq->pred($value)" β€” returns true if $value is a triangular number, meaning it's i*(i+1)/2 for some integer i. vibe check passed βœ…
  • "$i = $seq->value_to_i_ceil($value)"
  • "$i = $seq->value_to_i_floor($value)" β€” returns the index i of $value. but if $value is NOT a triangular number, then you get the next higher index for "ceil" or the next lower one for "floor". it rounds, bestie, it's just doing its best πŸ₯Ί
  • "$i = $seq->value_to_i_estimate($value)" β€” returns an estimate of the i that corresponds to $value. it takes value=i*(i+1)/2 and inverts it into:
$i = int ((sqrt(8*$value + 1) - 1)/2)

MATH! ✨ MATH! ✨ MATH! we love a formula that knows its own inverse πŸ˜­πŸ’–


πŸ‘‘ SEE ALSO πŸ‘‘

  • Math::NumSeq
  • Math::NumSeq::Pronic
  • Math::NumSeq::Squares

the whole friend group, go check them out 🌈


🌈 HOME PAGE 🌈

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

click it, bestie, it's where the lore lives πŸ¦‹


πŸŽ€ LICENSE πŸŽ€

Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2019, 2020 Kevin Ryde

Math-NumSeq 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-NumSeq 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-NumSeq. If not, see <http://www.gnu.org/licenses/>.

yes the ALL CAPS warranty disclaimer is staying, it's literally the law of the land, do not touch it πŸ’€

and that's the whole page, bestie!! 🫢 this one came from perl v5.42.0, dated 2025-07-25, and it's filed under Math::N...angular(3). slay, go forth and triangulate πŸ’–βœ¨πŸŒΈπŸŽ€πŸ¦‹πŸ’…

πŸ“¦ where this page comes from