danleyb2
2/27/2015 - 9:21 PM

mYscript.js

//this is a simple script that takes in two value, the product and sum of two numbers in a
//quadratic equation and tries to solve for the values to be used in solving the equation


function PpSp(p,s){
    big:for (var i=1;i<p;i++){
        for(var j=1;j<p;j++){
            if ((i*j)==p){
                if ((i+j)==s){
                   // System.out.println("I got it. The numbers are "+i+" and "+j);
                    break big;
                }
            }
        }
        if (i==(p-1)){
            System.out.println("There is no solution for this one");
        }
    }

}
function PpSn(p,s){
    big:for (var i=-1;i>=(p*-1);i--){

        for (var j=-1;j>(p*-1);j--) {
            if ((i*j)==p){
                if (i+j==s){
                    //Sys
                    break  big;
                }
            }
        }
    }

}
function PnSn(p,s){
    big:for (var i=1;i<Math.abs(p);i++){
        for (var j=1;j<Math.abs(p);j++){

            if ((j*i)==Math.abs(p)){
                //int t=j*-1;
                if (i>j){
                    i=(i*-1);
                    if ((i+j)==s){
                        // " + j);
                        break  big;}
                }else {
                    j = (j * -1);
                    if ((i + j) == s) {
                        //System.out.println(i + " " + j);
                        break  big;
                    }
                }
            }
        }


    }


}
function PnSp(p,s){
    big:for (var i=1;i<Math.abs(p);i++){
        for (var j=1;j<Math.abs(p);j++){

            if ((j*i)==Math.abs(p)){
                if (i<j){
                    i=(i*-1);
                    if ((i+j)==s){
                        //System.out.println(i + " " + j);
                        break  big;}
                }else {
                    j = (j * -1);
                    if ((i + j) == s) {
                        //System.out.println(i + " " + j);
                        break  big;
                    }
                }
            }
        }


    }

}