View Source Multitool.Numbers (multitool v0.3.4)

The Numbers module holds helper functions for number operations such as primes and factors

Link to this section Summary

Functions

Shifts all digits one place to the right, bringing the right most digit to the leftmost position

Shifts all digits to the right, repeated a given number of times.

Generates a MapSet of numbers resulting from cycling the given number so each digit is in each position once

Evaluates if a number is greater than negative one and does not have a remainder

Returns the given number without the leftmost digit

Returns the given number without the rightmost digit

Link to this section Functions

Shifts all digits one place to the right, bringing the right most digit to the leftmost position

If the operation of bringing the rightmost digit to the leftmost position would result in the leading number of the resulting integer being a zero, the digits are repeatedly shifted until a zero is not in the leftmost position

parameters

Parameters

n: The integer to cycle

examples

Examples

iex> cycle(57)
75

iex> cycle(-57) 
-75

iex> cycle(190)
901
Link to this function

cycle(n, c)

View Source (since 0.3.1)

Shifts all digits to the right, repeated a given number of times.

This operation operates the same as cycle/1 regarding leading zeroes

If the operation of bringing the rightmost digit to the leftmost position would result in the leading number of the resulting integer being a zero, the digits are repeatedly shifted until a zero is not in the leftmost position

parameters

Parameters

n: The integer to cycle
c: The amount of times to apply the cycle operation

examples

Examples

iex> cycle(57, 1)
75

iex> cycle(-57, 2) 
-57

iex> cycle(190, 2)
190

Generates a MapSet of numbers resulting from cycling the given number so each digit is in each position once

This operation operates the same as cycle/1 regarding leading zeroes

If the operation of bringing the rightmost digit to the leftmost position would result in the leading number of the resulting integer being a zero, the digits are repeatedly shifted until a zero is not in the leftmost position

parameters

Parameters

n: The integer to generate cycles of

examples

Examples

iex> cycles(123) |> MapSet.to_list()
[123, 231, 312]

iex> cycles(-57)  |> MapSet.to_list()
[-75, -57]
Link to this function

natural?(n)

View Source (since 0.3.1)

Evaluates if a number is greater than negative one and does not have a remainder

parameters

Parameters

n: Integer to evaluate for naturalness 

examples

Examples

iex> natural?(-5)
false

iex> natural?(7) 
true

iex> natural?(7.5)
false

iex> natural?(7.0)
true
Link to this function

trim_left(n)

View Source (since 0.3.1)

Returns the given number without the leftmost digit

When the given number is between negative nine and nine, zero is returned

parameters

Parameters

n: Integer to trim the leftmost digit off of

examples

Examples

iex> trim_left(57689)
7689

iex> trim_left(7) 
0

iex> trim_left(-56788)
-6788

iex> trim_left(-3)
0
Link to this function

trim_right(n)

View Source (since 0.3.1)

Returns the given number without the rightmost digit

When the given number is between negative nine and nine, zero is returned

parameters

Parameters

n: Integer to trim the rightmost digit off of

examples

Examples

iex> trim_right(57689)
5768

iex> trim_right(7) 
0

iex> trim_right(-56788)
-5678

iex> trim_right(-3)
0