View Source Multitool.Numbers.Triangular (multitool v0.3.0)

Provides operations for working with triangular numbers

A triangular number is generated by adding the natural numbers up to and including the number n.

The 4th triangular number, for example, can be calculated as follows:

1 + 2 + 3 + 4 = 10

Link to this section Summary

Functions

Returns the nth triangle number where the first triangle number is one.

Returns a list of the first n triangle numbers, starting at one

Link to this section Functions

Link to this function

nth_triangle_num(n)

View Source (since 0.1.0)

Returns the nth triangle number where the first triangle number is one.

If n is less than one, zero is returned

parameters

Parameters

n: The nth triangle number to retrieve

examples

Examples

iex> nth_triangle_num(3)
6
iex> nth_triangle_num(-1)
0
iex> nth_triangle_num(34)
595
Link to this function

triangle_nums(n)

View Source (since 0.1.0)

Returns a list of the first n triangle numbers, starting at one

If n is less than one, an empty list is returned

parameters

Parameters

n: The number of triangle numbers to retrieve

examples

Examples

iex> triangle_nums(3)
[1, 3, 6]
iex> triangle_nums(-1)
[]
iex> triangle_nums(5)
[1, 3, 6, 10, 15]