Package Exports
- pythagorean-triples
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pythagorean-triples) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
pythagorean-triples
Install
var triples = require('pythagorean-triples');
Usage
triples.euclid(m, n)
Generates a Pythagorean triple, using Euclid's formula a = m^2 - n^2, b = 2mn, c = m^2 + n^2
.
The returned triple is sorted numerically a < b < c
.
console.log(triples.euclid(2, 1)); // [3, 4, 5]
console.log(triples.euclid(3, 2)); // [5, 12, 13]
triples.upToM(m)
Generates all the triples for integers m
and n
where 1 <= n < m
.
console.log(triples.upToM(4));
[
[ 3, 4, 5 ],
[ 6, 8, 10 ],
[ 5, 12, 13 ],
[ 8, 15, 17 ],
[ 12, 16, 20 ],
[ 7, 24, 25 ]
]
triples.upToSum(sum)
Generates all the triples where a + b + c <= sum
.
console.log(triples.upToSum(35))
[
[ 3, 4, 5 ],
[ 6, 8, 10 ],
[ 5, 12, 13 ],
]