pykot/jmath

Search:
Group by:

Math-related things, e.g. check if a number is prime.

Procs

func is_prime(n: Positive): bool {....raises: [], tags: [], forbids: [].}

Decide whether a number is prime or not.

This is not an efficient implementation.

Example:

doAssert 1.is_prime == false
doAssert 2.is_prime == true
doAssert 3.is_prime == true
doAssert 4.is_prime == false
doAssert 5.is_prime == true
doAssert 97.is_prime == true
doAssert 100.is_prime == false
func to_digits(n: int): seq[int] {....raises: [], tags: [], forbids: [].}

Get the digits of a number.

For negative numbers, we work with the absolute value. The digits are returned in a reverse order.

Example:

doAssert 123.to_digits == @[3, 2, 1]
doAssert 2025.to_digits == @[5, 2, 0, 2]
doAssert 0.to_digits == @[0]
doAssert -42.to_digits == @[2, 4]