Polynomial Code

Steven J Miller (sjm1@williams.edu)
This code has the user input numpoints points on a polynomial of degree numpoints-1, and then determines the coefficients of that polynomial. 
Inspired by the following riddle:
Consider an army with 10 generals. One wants a security system such that any three of them can determine the code to launch nuclear missiles, but no two of them can. It is possible to devise such a system by using a quadratic polynomial, such as a x^2 + bx + c; to launch the missiles, one must input (a,b,c). One cannot just tell each general one of a, b, or c (as then it is possible that some subset of three generals won’t know a, b and c); however, if a general knows two of (a,b,c), then a set of two generals can launch the missiles! What information should be given to the generals so that any three can find (a,b,c) but no two can? What about the general situation with N generals and any M can launch (but no set of M-1) can?
Webpage: https://mathriddles.williams.edu/?p=107

findpolynomial[numpoints_] := Module[{},
Print["When asked to input your point, write it as {x-coord, y-coord}. Thus the point with x-coord 3 and y-coord 4 would be written {3,4}."];
points = {};
For[n = 1, n ≤ numpoints, n++,
{
Print["Enter Point ", n, "."];
temp= Input["Please enter point in form {x-coord, y-coord}"];
points = AppendTo[points, temp];
}];
(* Print[points] *)
M = {};
yvec = {};
For[n=1, n ≤ numpoints, n++,
{
x = points[[n,1]];
y = points[[n,2]];
yvec = AppendTo[yvec, y];
temp = {};
For[d = numpoints - 1, d ≥ 0, d = d - 1, If[x ==  0 && d == 0,temp = AppendTo[temp,1], temp = AppendTo[temp,x^d]]];
Print[temp];
M = AppendTo[M,temp];
}]; (* end of n looop *)
soln = Inverse[M].yvec;
(*Print[soln];*)
For[d = 1, d ≤ numpoints, d++,
Print["Coeffient a(",numpoints-d,") = ", soln[[d]], "."];
];
];

findpolynomial[4]

f[t_] := 2 t^3 + 5 t^2 - 3 t - 4
f[0]
f[1]
f[2]
f[3]

generatepoints[degree_,numpoints_] := Module[{},
Print["Enter the coefficients as a list: {a(d), a(d-1), ..., a(1), a(0)}. Thus if you have the polynomial 3x^2 - 8x + 7 you enter {3,-8,7}."];
points = {};
coefficients = {};
temp= Input["Please enter coefficients: {a(d), a(d-1), ..., a(1), a(0)}."];
coefficients = AppendTo[coefficients, temp];
(* Print[points] *)
For[n = 1, n ≤ numpoints, n++,
{
(* issues with 0^0 so do points 1, 2, 3, ...*)
Print["Point ",n, ": (", n, ", ", Sum[coefficients[[1,degree+1-d]] n^d,{d,0,degree}], ")."];
}]; (* end of n loop *)

];

generatepoints[2,5]

f[t_] := 3 t^2 + 2 t - 5
f[1]
f[2]
f[3]
f[4]
f[5]