(*This notebook shows which quadratics of the form ax^2+bx+c have Rational and Integer solutions where a,b,c are all Integers.  The grid is coloured Green for Integers, Blue for Rationals and and Red for Neither.*)
(*Now,let's see which quadratics have Rational solutions*)

Manipulate[RationalQ[x_]:=(Head[x]===Rational||IntegerQ[x]);
IntegerFactorsQ[a_,b_,c_]:=Module[{test},sols=x/.Solve[a x^2+b x+c==0];
Switch[Length[sols],2,If[IntegerQ[sols[[1]]]&&IntegerQ[sols[[2]]],"Y",If[RationalQ[sols[[1]]]&&RationalQ[sols[[2]]],"R","N"]],1,If[IntegerQ[sols[[1]]],"Y",If[RationalQ[sols[[1]]],"R","N"]],0,"N"]];
data=Table[IntegerFactorsQ[a,b,c],{c,-10,10},{b,-10,10}];
(*Add Labels to Rows*)data=MapIndexed[Prepend[#1,#2[[1]]-11]&,data];
(*Add Labels to columns*)PrependTo[data,Flatten[{" ",Table[x,{x,-10,10}]}]];
(*Generate colour specification for each cell*)backgroundSpec=Table[Switch[data[[x,y]],"Y",{x,y}->Green,"N",{x,y}->Red,"R",{x,y}->Blue],{x,2,22},{y,2,22}];
(*Create the grid of data*)outputGrid=Grid[data,Frame->All,Background->{None,None,Flatten[backgroundSpec]},ItemSize->1.8];
(*Create final output including labels*)Grid[{{Style["a="<>ToString[a],{Bold,FontSize->20}],Style["Factoring \!\(\*SuperscriptBox[\"ax\", \"2\"]\)+bx+c",{Bold,FontSize->20}]},{" ",Style["b",{Bold,FontSize->20}]},{Style["c",{Bold,FontSize->20}],outputGrid}}],{{a,1},-9,9,1,Appearance->"Labeled"},TrackedSymbols:>{a},SaveDefinitions->True]