Triangle( 3 ) = | + | Triangle( ) | ||

Triangle( 2 ) = | + | Triangle( ) | ||

Triangle( 1 ) = | ||||

Triangle( 2 ) = | + | |||

Triangle( 3 ) = | + | |||

Triangle( 3 ) = |

Here is our solution for triangle numbers:

- Triangle( 1 ) = 1
- Triangle( N ) = N + Triangle( N-1 )

Here is another example, calculating `Triangle( 5 )`

:

Triangle( 5 ) = 5 + Triangle( 4 ) = 5 + ( 4 + Triangle( 3 ) ) = 5 + ( 4 + ( 3 + Triangle( 2 ) )) = 5 + ( 4 + ( 3 + ( 2 + Triangle( 1 ) ))) = 5 + ( 4 + ( 3 + ( 2 + 1 ))) = 5 + ( 4 + ( 3 + 3) ) = 5 + ( 4 + 6 ) = 5 + 10 = 15