How this calculation works
The index tells how many rows a triangular dot pattern has when row sizes run from 1 up to that index.
n is triangular when 8n + 1 is an odd perfect squareA worked example
55 = 1 + 2 + … + 10.
Good to know
Zero is treated as the zeroth triangular number.
Reference: NIST DLMF, Functions of Number Theory (opens in a new tab) ↗
Recover the triangle index from the total
A triangular number counts rows containing 1, 2, 3 and so on up to k objects. The total is k(k + 1)/2. For the default input 55, solving this equation gives k = (√(8 × 55 + 1) − 1)/2 = (21 − 1)/2 = 10. Thus 55 is the tenth triangular number.
The discriminant 8n + 1 must be an odd perfect square for a nonnegative integer index to exist. For 56 it is 449, whose square root is not an integer, so the test fails. The candidate index is a diagnostic value; only an integer candidate establishes a triangular representation.
Check the sum by pairing terms
The ten rows for 55 can be paired as 1 + 10, 2 + 9, 3 + 8, 4 + 7 and 5 + 6. Five pairs of 11 give 55. Pairing an increasing sequence with its reverse explains the factor of one half in k(k + 1)/2.
The Consecutive integers from a sum calculator recovers a run with a specified number of terms. A triangular number specifically uses the run starting at one. Zero is accepted here as the zeroth triangular number, corresponding to no rows. The diagram uses five rows totaling 15 so that each object is visible, while the default numerical test concerns ten rows totaling 55.
A few questions, answered
Are all squares triangular?
No. Four is a square but not triangular. Thirty-six is both because it equals 1 + 2 + … + 8.
How do I check the returned index?
Substitute the integer candidate k into k(k + 1)/2 and confirm that the result equals your input.