Giter Club home page Giter Club logo

kevduc / diophantine Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 888 KB

๐Ÿงฎ Solve linear Diophantine equations of the form ax + by = c

Home Page: https://kevduc.github.io/diophantine/

License: ISC License

JavaScript 66.81% CSS 33.19%
maths mathematics diophantine diophantine-solver diophantine-equation diophantine-equations equation equations equation-solver equations-solver solve solver solving solving-algorithm linear linear-equation linear-equations linear-equation-solver linear-equations-solution linear-solutions

diophantine's Introduction

diophantine

๐Ÿงฎ Solve linear Diophantine equations of the form ax + by = c

npm package documentation downloads open issues build last commit license donate with crypto

๐Ÿ“ฆ npm: npm i diophantine โ€“ npmjs.com/diophantine
๐Ÿ“˜ Documentation: kevduc.github.io/diophantine
๐Ÿฑโ€๐Ÿ’ป GitHub: kevduc/diophantine

๐Ÿ‘‡ Example

example.js

const { dioSolve, SolutionType } = require('diophantine')

const a = 59
const b = -7
const c = 4

console.log(`Solving: ${a}x + ${b}y = ${c}`)

const { solutionType, g, z, m, p } = dioSolve(a, b, c)

switch (solutionType) {
  case SolutionType.None: {
    console.log(`No solution (gcd = ${g} โˆค c = ${c})`)
    break
  }
  case SolutionType.Unique: {
    console.log(`Unique solution: ${z[0] !== null ? `x = ${z[0]}` : `y = ${z[1]}`}`)
    break
  }
  case SolutionType.Linear: {
    console.log(`   gcd = ${g}`)
    console.log(`   x0 = ${z[0]}, y0 = ${z[1]}`)
    console.log(`   ${a} ร— ${z[0]} + ${b} ร— ${z[1]} = ${z[0] * a + z[1] * b}`)
    console.log(`Solutions: x = ${m[0]}n + ${p[0]}, y = ${m[1]}n + ${p[1]}`)
    break
  }
  default: {
    console.log(`Solution: ${solutionType}`)
    break
  }
}

Console output

Solving: 59x + -7y = 4
  gcd = 1
  x0 = -8, y0 = -68
  59 ร— -8 + -7 ร— -68 = 4
Solutions: x = 7n + 6, y = 59n + 50

โ˜• Support the dev

Donate a hot chocolate with crypto

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.