View Source Multitool.Numbers.Figurate (multitool v0.3.4)
Provides operations for working with figurate numbers
Link to this section Summary
Functions
Given a positive integer n, returns the nth hexagonal number
Given an Integer n, returns the position of the number in the hexagonal sequence
Returns a List of the first n hexagonal numbers
Given a positive integer n, returns the nth pentagonal number
Given an Integer n, returns the position of the number in the pentagonal sequence
Returns a List of the first n pentagonal numbers
Given a positive integer n, returns the nth triangle number
Given an Integer n, returns the position of the number in the triangular sequence
Returns a List of the first n triangle numbers
Link to this section Functions
Given a positive integer n, returns the nth hexagonal number
Negative integers return nil
parameters
Parameters
n: Integer. The nth hexagonal number to return
examples
Examples
iex> hexagonal(5)
45
iex> hexagonal(-4)
nil
Given an Integer n, returns the position of the number in the hexagonal sequence
Negative integers or integers not in the sequence return nil
parameters
Parameters
n: Integer. The number to test for being a hexagonal number
examples
Examples
iex> hexagonal?(630)
18
iex> hexagonal?(-4)
nil
iex> hexagonal?(29)
nil
Returns a List of the first n hexagonal numbers
Providing a negative integer returns an empty List
parameters
Parameters
n: Integer. The number of hexagonal numbers to generate
examples
Examples
iex> hexagonals(3)
[1, 6, 15]
iex> hexagonals(-4)
[]
Given a positive integer n, returns the nth pentagonal number
Negative integers return nil
parameters
Parameters
n: Integer. The nth pentagonal number to return
examples
Examples
iex> pentagonal(5)
35
iex> pentagonal(-4)
nil
Given an Integer n, returns the position of the number in the pentagonal sequence
Negative integers or integers not in the sequence return nil
parameters
Parameters
n: Integer. The number to test for being a pentagonal number
examples
Examples
iex> pentagonal?(70)
7
iex> pentagonal?(-4)
nil
iex> pentagonal?(29)
nil
Returns a List of the first n pentagonal numbers
Providing a negative integer returns an empty List
parameters
Parameters
n: Integer. The number of pentagonal numbers to generate
examples
Examples
iex> pentagonals(3)
[1, 5, 12]
iex> pentagonals(-4)
[]
Given a positive integer n, returns the nth triangle number
Negative integers return nil
parameters
Parameters
n: Integer. The nth triangle number to return
examples
Examples
iex> triangle(5)
15
iex> triangle(-4)
nil
Given an Integer n, returns the position of the number in the triangular sequence
Negative integers or integers not in the sequence return nil
parameters
Parameters
n: Integer. The number to test for being a triangle number
examples
Examples
iex> triangle?(630)
35
iex> triangle?(-4)
nil
iex> triangle?(29)
nil
Returns a List of the first n triangle numbers
Providing a negative integer returns an empty List
parameters
Parameters
n: Integer. The number of triangle numbers to generate
examples
Examples
iex> triangles(3)
[1, 3, 6]
iex> triangles(-4)
[]