2018-06-29 16:10:38 +02:00
|
|
|
let Polynomial = require('./polynomial.js');
|
|
|
|
let mul, div, gcd;
|
2018-06-29 19:35:57 +02:00
|
|
|
|
|
|
|
function parseArray(x) {
|
2018-06-29 19:52:23 +02:00
|
|
|
let stringResult = "";
|
2018-06-29 19:35:57 +02:00
|
|
|
result = Array.from(x).filter(x => {
|
2018-06-29 19:52:23 +02:00
|
|
|
if (x == ' ' || x == '[' || x == ']') return false;
|
2018-06-29 19:35:57 +02:00
|
|
|
else return true;
|
2018-06-29 19:52:23 +02:00
|
|
|
}).join('').split(',').map(x => parseInt(x));
|
2018-06-29 19:35:57 +02:00
|
|
|
return result;
|
|
|
|
}
|
2018-06-29 16:10:38 +02:00
|
|
|
|
|
|
|
let n = parseInt(process.argv[2]);
|
2018-06-29 19:35:57 +02:00
|
|
|
let p1 = parseArray(process.argv[3]);
|
|
|
|
let p2 = parseArray(process.argv[4]);
|
|
|
|
|
2018-07-01 11:35:34 +02:00
|
|
|
let f = new Polynomial.Class(n, p1);
|
|
|
|
let g = new Polynomial.Class(n, p2);
|
|
|
|
mul = Polynomial.multiply(f, g).coefficients;
|
2018-06-29 16:10:38 +02:00
|
|
|
try {
|
2018-07-01 11:35:34 +02:00
|
|
|
div = Polynomial.divide(f, g).coefficients
|
2018-06-29 16:10:38 +02:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e)
|
|
|
|
}
|
|
|
|
try {
|
2018-07-01 11:35:34 +02:00
|
|
|
gcd = Polynomial.gcd(f, g).coefficients;
|
2018-06-29 16:10:38 +02:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
console.log([mul, div, gcd])
|