@danilosampaio/numbers
v1.0.2
Published
A lib for math calculations.
Downloads
5
Maintainers
Readme
Numbers
A library for math calculations.
Summary
- Binomial Coefficient
- Congruences
- Diophantine Equations
- Factorial
- Great common divisor
- Least common multiple
- Primes
- Triangular numbers
Install
npm install @danilosampaio/numbers
Binomial coefficient
Usage
const { binomialCoefficient } = require('@danilosampaio/numbers');
// a = 4, b = 2
binomialCoefficient(4, 2);
// => 6
Congruences
Usage
const { congruences } = require('@danilosampaio/numbers');
// 3 ≡ 24 (mod 7)
congruences(3, 24, 7);
// => true
Diophantine Equations
Usage
const { diophantineEquation } = require('@danilosampaio/numbers');
// 3x + 6y = 18
diophantineEquation.hasSolution(3, 6, 18);
// => true
// The nth solution for 172x + 20b = 1000 | x0 = 500, y0 = -4250, t = 1
diophantineEquation.nthSolution(172, 20, 1000, 500, -4250, 1);
// => [505, -4293]
Factorial
Usage
const { factorial } = require('@danilosampaio/numbers');
// 5!
factorial(5);
// => 120
Great common divisor
Usage
const { greatCommonDivisor } = require('@danilosampaio/numbers');
// a = 12378, b = 3054
greatCommonDivisor(12378, 3054);
// => 6
Least common multiple
Usage
const { leastCommonMultiple } = require('@danilosampaio/numbers');
// a = 4, b = 6
leastCommonMultiple(4, 6);
// => 12
Primes
Usage
const { primes } = require('@danilosampaio/numbers');
// p = 5
primes.isPrime(5);
// => true
Triangular numbers
Usage
const { triangularNumber } = require('@danilosampaio/numbers');
// n = 6
triangularNumber.isTriangularNumber(6);
// => true
// The sixth triangular number
triangularNumber.nth(6);
// => 21
License
MIT