Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tom-weatherhead/number-theory-js

A library of JavaScript implementations of number theory utilities.
https://github.com/tom-weatherhead/number-theory-js

math mathematics number-theory prime-factors prime-numbers

Last synced: about 7 hours ago
JSON representation

A library of JavaScript implementations of number theory utilities.

Awesome Lists containing this project

README

        

# number-theory-js

[![build status](https://secure.travis-ci.org/tom-weatherhead/number-theory-js.svg)](http://travis-ci.org/tom-weatherhead/number-theory-js)

number-theory-js is a library of JavaScript implementations of number theory utilities.

Most of this project's infrastructure was stolen from Jason Mulligan's ([avoidwork](https://github.com/avoidwork)'s) [tiny-graph](http://avoidwork.github.io/tiny-graph) project.

## Example
```javascript
const engine = require('number-theory-js');

console.log(engine.factorize(72)); // [2, 2, 2, 3, 3]

console.log(engine.gcd(35, 84)); // 7

console.log(engine.sieve(20)); // [2, 3, 5, 7, 11, 13, 17, 19]
```

## How can I use number-theory-js?
number-theory-js can be installed from npm and bower, and supports AMD loaders or script tags (e.g. `window.sieve`).

## API
#### gcd(m, n)
Returns the greatest common divisor of integers `m` and `n`, calculated using Euclid's algorithm

#### factorize(n)
Returns the unique prime factorization of `n` as a list of integers

#### sieve(n)
Returns the list of all prime numbers less than `n`, calculated using the Sieve of Eratosthenes

#### totient(n)
Euler's totient function: Returns the list of all positive integers less than `n` that are relatively prime to `n`

## License
Copyright (c) 2018 Tom Weatherhead
Licensed under the MIT license