JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q62251F
  • License ISC

Generates Pythagorean triples using Euclid's formula

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)

Uses Euclid's formula a = m^2 - n^2, b = 2mn, c = m^2 + n^2 to generate a triple.

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 ] ]