
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 0.57 KB | hits: 18 | expires: Never
<!DOCTYPE html>
<title>solveAlgebraicEquation</title>
<div>Output: <b id="ret"></b></div>
<script>
var myFunction = function(a,b,c,d,e){c="^";for(d=0;e=a[d++];)c+="(,*)\\"+d+"{"+~-e+"}";return((Array(-~b)+"").match(c+"$")||"").slice(1)};
// The input should be ([a, b, c, ...], sum)
// e.g. Solve 11x + 2y + 5z = 115
var solution = myFunction([11, 2, 5], 115);
document.getElementById( "ret" ).innerHTML = 'One of the solutions of 11x + 2y + 5z = 115 is x = ' +
solution[0].length + ', y = ' +
solution[1].length + ', z = ' +
solution[2].length;
</script>