1
0
forked from kalmar/DALGLI0
DALGLI0/02-rozwiazanie.js

30 lines
754 B
JavaScript
Raw Normal View History

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]);
let f = new Polynomial.Class(p1);
let g = new Polynomial.Class(p2);
2018-06-29 16:10:38 +02:00
mul = Polynomial.multiply(f, g, 2).coefficients;
try {
div = Polynomial.divide(f, g, 2).coefficients
} catch (e) {
console.log(e)
}
try {
gcd = Polynomial.gcd(f, g, 2).coefficients;
} catch (e) {
console.log(e);
}
console.log([mul, div, gcd])