Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
pythagorean-triples
Advanced tools
Readme
$ npm install pythagorean-triples
var triples = require('pythagorean-triples');
Generates a Pythagorean triple, using Euclid's formula a = m^2 - n^2, b = 2mn, c = m^2 + n^2
.
The 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]
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 ]
]
Generates all the triples where a + b + c <= sum
.
console.log(triples.upToSum(35))
[
[ 3, 4, 5 ],
[ 6, 8, 10 ],
[ 5, 12, 13 ],
]
Checks if the given triple is a valid triple:
a^2 + b^2 = c^2
console.log(triples.isTriple([3, 4, 5]); //true
console.log(triples.isTriple([5, 12, 13]); // true
console.log(triples.isTriple('5, 12, 13'); // false, not an array
console.log(triples.isTriple([5, 13]); // false, too few values
console.log(triples.isTriple([5, 12, 13, 15]); // false, too many values
console.log(triples.isTriple([1.5, 2, 2.5]); // false, non-integers
console.log(triples.isTriple([-5, 12, 13]); // false, not all positive values
console.log(triples.isTriple([0, 7, 7]); // false, not all positive values
console.log(triples.isTriple([5, 12, 15]); // false, cannot make a right angle
Checks if the given triple is primitive. A triple is primitive if all values are coprime, which means their greatest common divisor is 1.
console.log(triples.isPrimitive([3, 4, 5]); //true
console.log(triples.isPrimitive([6, 8, 10]); // false
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test
FAQs
Generate Pythagorean triples using Euclid's formula
The npm package pythagorean-triples receives a total of 3 weekly downloads. As such, pythagorean-triples popularity was classified as not popular.
We found that pythagorean-triples demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.