Math::N...angular(3)
β¨ 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$valueis a triangular number, meaning it'si*(i+1)/2for 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$valueis 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 takesvalue=i*(i+1)/2and 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::NumSeqMath::NumSeq::PronicMath::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
- fedora 43: perl-Math-NumSeq 75-11.fc43 Β· 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