Problem 5. Triangle Numbers
Triangle numbers are the sums of successive integers. So 6 is a triangle number because
6 = 1 + 2 + 3
which can be displayed in a triangular shape like so
*
* *
* * *
Thus 6 = triangle(3). Given n, return t, the triangular number for n.
Example:
Input n = 4
Output t is 10
Solution Stats
Problem Comments
-
26 Comments
Show
23 older comments
Ian
on 11 Dec 2022
+10 points
Anirban Kar Roy
on 5 Apr 2025 at 8:57
Good question :)
yuyuyu
on 25 Apr 2025 at 11:25
You might know this as the Triangular Number formula—or as some folks call it, the Gauss Summation trick—for adding numbers 1 through n super fast!
Solution Comments
Show commentsGroup

Rubik's Cube
- 11 Problems
- 1 Finishers
- Perform Rubik's Cube Moves
- Solve Rubik's Cube - One Rotation
- Solve Rubik's Cube - Up to Two Face Moves
- Rubik's Cube : Solve Ten Face Move - Speed Scoring
- Rubik's Cube: Solve Randomized Cube - Score : Moves
- Rubik's Mini-Cube: Solve Randomized Mini-Cube - Score : Moves
- Rubik's Mini Cube: Solve Randomized Cube in 11 Moves or Less; Score is by Time (msec)
- Rubik's Cube: 30 Moves or Less : Minimum Moves
- Rubik's Cube: 30 Moves or Less: Minimum Avg Time
- Rubik's Cube: 30 Moves or Less : Cody Size
- Rubik's Cube: 30 Moves or Less : Contest Scoring (Time/Size/Moves)
Problem Recent Solvers28481
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!