This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getIndex = (permutation, affected) => { | |
const indexes = affected.map(i => permutation.indexOf(i)); | |
if (affected.length === 1) { | |
return permutation.indexOf(affected[0]); | |
} | |
let base = permutation.length; | |
let index = indexes[indexes.length - 1]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var NumberTheory = {}; | |
/** | |
* @param {number} n | |
* @param {number} k | |
*/ | |
NumberTheory.binomial = function(n, k) { | |
if (n === k) return 1; | |
if (k === 1) return n; | |
return binomial(n - 1, k) + binomial(n - 1, k - 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prototype that stores information about a given polynomial. | |
function Polynomial(data) { | |
// Support providing already existing Polynomials. | |
this.polynomial = data instanceof Polynomial ? data.polynomial : data; | |
} | |
// Rank all coefficients in the polynomial and return the largest. | |
Polynomial.prototype.getLargestCoefficient = function() { | |
var re = /(\d+)/g, match, max = 0; | |
while(match = re.exec(this.getPolynomial())) |