Skip to content

Instantly share code, notes, and snippets.

@Nekodigi
Created December 26, 2020 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nekodigi/e3ec2e03f762512454d0d2d73cef604b to your computer and use it in GitHub Desktop.
Save Nekodigi/e3ec2e03f762512454d0d2d73cef604b to your computer and use it in GitHub Desktop.
//generate coefficients from answers. it's just like expansion of formula.
Complex[] coeffsFromAns(Complex ... answers){
Complex[] coeffs = new Complex[2];
coeffs[0] = answers[0].mult(-1);
coeffs[1] = c(1, 0);
for(int i=1; i<answers.length; i++){
Complex[] f = {answers[i].mult(-1), r(1)};
coeffs = formulaMult(coeffs, f);
}
return coeffs;
}
//Multiplication of formula
Complex[] formulaMult(Complex[] f1, Complex[] f2){
Complex[] result = new Complex[f1.length+f2.length-1];
for(int i=0; i<=f1.length-1+f2.length-1; i++){
result[i] = c(0, 0);
println(i, max(i-(f2.length-1), 0), min(i, f1.length-1));
for(int j=max(i-(f2.length-1), 0); j<=min(i, f1.length-1); j++){
result[i] = result[i].add(f1[j].mult(f2[i-j]));
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment