Cell[CellGroupData[{Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"Liner", "[", RowBox[{"{", RowBox[{"pt1_", ",", "pt2_"}], "}"}], "]"}], ":=", " ", RowBox[{"Simplify", "[", RowBox[{ RowBox[{"Det", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"x", ",", "y", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"First", "[", "pt1", "]"}], ",", RowBox[{"Last", "[", "pt1", "]"}], ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"First", "[", "pt2", "]"}], ",", RowBox[{"Last", "[", "pt2", "]"}], ",", "1"}], "}"}]}], "}"}], "]"}], "/", " ", RowBox[{"(", RowBox[{"GCD", "@@", RowBox[{"Flatten", "[", RowBox[{"CoefficientList", "[", RowBox[{ RowBox[{"Det", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"x", ",", "y", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"First", "[", "pt1", "]"}], ",", RowBox[{"Last", "[", "pt1", "]"}], ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"First", "[", "pt2", "]"}], ",", RowBox[{"Last", "[", "pt2", "]"}], ",", "1"}], "}"}]}], "}"}], "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "y"}], "}"}]}], "]"}], "]"}]}], ")"}]}], "]"}]}], ";"}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, InitializationCell->True, CellChangeTimes->{3.760765629130434*^9}, CellID->47796048], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"ReturnLines", "[", "ptList_", "]"}], " ", ":=", RowBox[{"Select", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Union", "[", RowBox[{"Flatten", "[", RowBox[{ RowBox[{"Last", "[", "#", "]"}], ",", "1"}], "]"}], "]"}], "&"}], "/@", RowBox[{"(", RowBox[{"Transpose", "/@", RowBox[{"SplitBy", "[", RowBox[{ RowBox[{"Sort", "[", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Liner", "[", "#", "]"}], ",", "#"}], "}"}], "&"}], "/@", RowBox[{"Subsets", "[", RowBox[{ RowBox[{"Union", "[", "ptList", "]"}], ",", RowBox[{"{", "2", "}"}]}], "]"}]}], "]"}], ",", "First"}], "]"}]}], ")"}]}], ",", RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], ">", "2"}], "&"}]}], "]"}]}], ";"}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, InitializationCell->True, CellChangeTimes->{{3.5612987846769314`*^9, 3.5612988137339315`*^9}, { 3.561298862626931*^9, 3.561298911569931*^9}, { 3.5612990686371593`*^9, 3.561299221188011*^9}, 3.5612992549829893`*^9, {3.5612993056547174`*^9, 3.5612993092390757`*^9}, 3.76076562913055*^9}, CellID->553701263], Cell[BoxData[ RowBox[{ RowBox[{"UnsortedUnion", "[", "x_", "]"}], ":=", RowBox[{ RowBox[{"Reap", "[", RowBox[{ RowBox[{"Sow", "[", RowBox[{"1", ",", "x"}], "]"}], ",", "_", ",", RowBox[{"#1", "&"}]}], "]"}], "[", RowBox[{"[", "2", "]"}], "]"}]}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, InitializationCell->True, CellChangeTimes->{3.760765629130652*^9}, CellID->248665759], Cell[BoxData[ RowBox[{ RowBox[{"solutions", " ", "=", " ", RowBox[{"{", " ", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "5"}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", "4"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "5"}], "}"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "4"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"4", ",", "4"}], "}"}], ",", RowBox[{"{", RowBox[{"5", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"6", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"7", ",", "1"}], "}"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", "4"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"4", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"4", ",", "6"}], "}"}], ",", RowBox[{"{", RowBox[{"5", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"5", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"6", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"6", ",", "5"}], "}"}], ",", RowBox[{"{", RowBox[{"7", ",", "6"}], "}"}], ",", RowBox[{"{", RowBox[{"7", ",", "8"}], "}"}], ",", RowBox[{"{", RowBox[{"8", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"8", ",", "8"}], "}"}], ",", RowBox[{"{", RowBox[{"9", ",", "4"}], "}"}], ",", RowBox[{"{", RowBox[{"9", ",", "5"}], "}"}]}], "}"}]}], "}"}]}], ";"}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, InitializationCell->True, CellChangeTimes->{ 3.35696210375764*^9, {3.3779762441429253`*^9, 3.377976299125638*^9}, {3.3779763610774603`*^9, 3.3779765274708905`*^9}, 3.760765629130755*^9}, CellID->196672633], Cell[BoxData[ RowBox[{"Manipulate", "[", " ", RowBox[{ RowBox[{ RowBox[{"SeedRandom", "[", "sr", "]"}], ";", RowBox[{"DynamicModule", "[", RowBox[{ RowBox[{"{", RowBox[{"data", "=", RowBox[{"If", "[", RowBox[{ RowBox[{"sr", "<", "4"}], ",", RowBox[{"Take", "[", RowBox[{ RowBox[{"UnsortedUnion", "[", RowBox[{"Join", "[", RowBox[{ RowBox[{"solutions", "[", RowBox[{"[", "sr", "]"}], "]"}], ",", RowBox[{"Table", "[", RowBox[{ RowBox[{"RandomInteger", "[", RowBox[{"{", RowBox[{"1", ",", "9"}], "}"}], "]"}], ",", RowBox[{"{", "60", "}"}], ",", RowBox[{"{", "2", "}"}]}], "]"}]}], "]"}], "]"}], ",", "25"}], "]"}], ",", RowBox[{"Take", "[", RowBox[{ RowBox[{"UnsortedUnion", "[", RowBox[{"Partition", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"RandomInteger", "[", RowBox[{"{", RowBox[{"1", ",", "9"}], "}"}], "]"}], ",", RowBox[{"{", "80", "}"}]}], "]"}], ",", "2"}], "]"}], "]"}], ",", "25"}], "]"}]}], "]"}]}], "}"}], ",", RowBox[{"LocatorPane", "[", RowBox[{ RowBox[{"Dynamic", "[", RowBox[{"data", "[", RowBox[{"[", RowBox[{"Range", "[", "n", "]"}], "]"}], "]"}], "]"}], ",", RowBox[{"Dynamic", "[", RowBox[{"Block", "[", RowBox[{ RowBox[{"{", RowBox[{"fit", ",", "x"}], "}"}], ",", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"poly", "=", RowBox[{"Map", "[", RowBox[{ RowBox[{ RowBox[{"Min", "[", RowBox[{"9", ",", RowBox[{"Max", "[", RowBox[{"{", RowBox[{"1", ",", RowBox[{"Round", "[", "#", "]"}]}], "}"}], "]"}]}], "]"}], "&"}], ",", RowBox[{"Take", "[", RowBox[{"data", ",", "n"}], "]"}], ",", RowBox[{"{", "2", "}"}]}], "]"}]}], "}"}], ",", RowBox[{"Graphics", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"AbsoluteThickness", "[", "3", "]"}], ",", RowBox[{ RowBox[{ RowBox[{"Switch", "[", RowBox[{ RowBox[{"Length", "[", "#", "]"}], ",", "3", ",", RowBox[{"{", RowBox[{ RowBox[{"RGBColor", "[", RowBox[{"1", ",", ".71", ",", "0"}], "]"}], ",", RowBox[{"Line", "[", "#", "]"}]}], "}"}], ",", "4", ",", RowBox[{"{", RowBox[{"Green", ",", RowBox[{"Line", "[", "#", "]"}]}], "}"}], ",", "__", ",", RowBox[{"{", RowBox[{"Red", ",", RowBox[{"Line", "[", "#", "]"}]}], "}"}]}], "]"}], "&"}], "/@", RowBox[{"ReturnLines", "[", "poly", "]"}]}], ",", RowBox[{"AbsolutePointSize", "[", "4", "]"}], ",", "Gray", ",", RowBox[{"Point", "/@", RowBox[{"Complement", "[", RowBox[{ RowBox[{"Flatten", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{"a", ",", "b"}], "}"}], ",", RowBox[{"{", RowBox[{"a", ",", "1", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"b", ",", "1", ",", "9"}], "}"}]}], "]"}], ",", "1"}], "]"}], ",", "poly"}], "]"}]}], ",", RowBox[{"AbsolutePointSize", "[", "12", "]"}], ",", RowBox[{"RGBColor", "[", RowBox[{".33", ",", ".26", ",", ".78"}], "]"}], ",", RowBox[{"Point", "/@", "poly"}]}], "}"}], ",", RowBox[{"PlotRange", "->", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{".5", ",", "9.5"}], "}"}], ",", RowBox[{"{", RowBox[{".5", ",", "9.5"}], "}"}]}], "}"}]}], ",", RowBox[{"ImageSize", "->", RowBox[{"{", RowBox[{"400", ",", "450"}], "}"}]}], ",", " ", RowBox[{"PlotLabel", "->", RowBox[{"Text", "@", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"linetypes", " ", "=", " ", RowBox[{"Length", "/@", RowBox[{"ReturnLines", "[", "poly", "]"}]}]}], "}"}], ",", " ", RowBox[{"Grid", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Flatten", "[", RowBox[{"{", RowBox[{"\"\\"", ",", RowBox[{"Range", "[", RowBox[{"3", ",", "9"}], "]"}]}], "}"}], "]"}], ",", RowBox[{"Flatten", "[", RowBox[{"{", RowBox[{"\"\\"", ",", RowBox[{"Table", "[", RowBox[{ RowBox[{"Count", "[", RowBox[{"linetypes", ",", "n"}], "]"}], ",", RowBox[{"{", RowBox[{"n", ",", "3", ",", "9"}], "}"}]}], "]"}]}], "}"}], "]"}]}], "}"}], ",", " ", RowBox[{"Frame", "->", " ", "All"}]}], "]"}]}], "]"}]}]}]}], "]"}]}], "]"}]}], "]"}], "]"}], ",", RowBox[{"Appearance", "->", "\"\<\>\""}]}], "]"}]}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"n", ",", "10", ",", "\"\\""}], "}"}], ",", "4", ",", "25", ",", "1", ",", RowBox[{"Appearance", "->", "\"\\""}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"sr", ",", "81", ",", "\"\\""}], "}"}], ",", "1", ",", "103", ",", "1", ",", RowBox[{"Appearance", "->", "\"\\""}]}], "}"}], ",", " ", RowBox[{"SaveDefinitions", "->", "True"}]}], "]"}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{ 3.35696210375764*^9, {3.378566825840248*^9, 3.3785668276313553`*^9}, {3.378568397501052*^9, 3.3785683987922773`*^9}, {3.380735811703125*^9, 3.380735846859375*^9}, {3.3813527628125*^9, 3.381352764484375*^9}, {3.382213234430908*^9, 3.382213252696533*^9}, 3.5003969362582703`*^9, 3.561296355567233*^9, {3.5612966271163855`*^9, 3.5612966314308167`*^9}, {3.5612966896916423`*^9, 3.561296695779251*^9}, 3.5612993382786803`*^9, 3.561299744699682*^9, {3.5612998210943213`*^9, 3.5612998572933893`*^9}, {3.5613000030341144`*^9, 3.561300008252636*^9}, {3.561300039066717*^9, 3.5613000428470955`*^9}, 3.760765629120503*^9}, CellID->37978384], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`n$$ = 10, $CellContext`sr$$ = 81, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{{ Hold[$CellContext`n$$], 10, "number of points"}, 4, 25, 1}, {{ Hold[$CellContext`sr$$], 81, "random seed"}, 1, 103, 1}}, Typeset`size$$ = {406., {225., 231.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = False, $CellContext`n$818$$ = 0, $CellContext`sr$819$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`n$$ = 10, $CellContext`sr$$ = 81}, "ControllerVariables" :> { Hold[$CellContext`n$$, $CellContext`n$818$$, 0], Hold[$CellContext`sr$$, $CellContext`sr$819$$, 0]}, "OtherVariables" :> { Typeset`show$$, Typeset`bookmarkList$$, Typeset`bookmarkMode$$, Typeset`animator$$, Typeset`animvar$$, Typeset`name$$, Typeset`specs$$, Typeset`size$$, Typeset`update$$, Typeset`initDone$$, Typeset`skipInitDone$$}, "Body" :> (SeedRandom[$CellContext`sr$$]; DynamicModule[{$CellContext`data = If[$CellContext`sr$$ < 4, Take[ $CellContext`UnsortedUnion[ Join[ Part[$CellContext`solutions, $CellContext`sr$$], Table[ RandomInteger[{1, 9}], {60}, {2}]]], 25], Take[ $CellContext`UnsortedUnion[ Partition[ Table[ RandomInteger[{1, 9}], {80}], 2]], 25]]}, LocatorPane[ Dynamic[ Part[$CellContext`data, Range[$CellContext`n$$]]], Dynamic[ Block[{$CellContext`fit, $CellContext`x}, With[{$CellContext`poly$ = Map[Min[9, Max[{1, Round[#]}]]& , Take[$CellContext`data, $CellContext`n$$], {2}]}, Graphics[{ AbsoluteThickness[3], Map[Switch[ Length[#], 3, { RGBColor[1, 0.71, 0], Line[#]}, 4, {Green, Line[#]}, BlankSequence[], {Red, Line[#]}]& , $CellContext`ReturnLines[$CellContext`poly$]], AbsolutePointSize[4], Gray, Map[Point, Complement[ Flatten[ Table[{$CellContext`a, $CellContext`b}, \ {$CellContext`a, 1, 9}, {$CellContext`b, 1, 9}], 1], $CellContext`poly$]], AbsolutePointSize[12], RGBColor[0.33, 0.26, 0.78], Map[Point, $CellContext`poly$]}, PlotRange -> {{0.5, 9.5}, {0.5, 9.5}}, ImageSize -> {400, 450}, PlotLabel -> Text[ With[{$CellContext`linetypes$ = Map[Length, $CellContext`ReturnLines[$CellContext`poly$]]}, Grid[{ Flatten[{"points in line", Range[3, 9]}], Flatten[{"occurrences", Table[ Count[$CellContext`linetypes$, $CellContext`n$$], \ {$CellContext`n$$, 3, 9}]}]}, Frame -> All]]]]]]], Appearance -> ""]]), "Specifications" :> {{{$CellContext`n$$, 10, "number of points"}, 4, 25, 1, Appearance -> "Labeled"}, {{$CellContext`sr$$, 81, "random seed"}, 1, 103, 1, Appearance -> "Labeled"}}, "Options" :> {}, "DefaultOptions" :> {ControllerLinking -> True}], ImageSizeCache->{451., {285., 291.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, Initialization:>({$CellContext`UnsortedUnion[ Pattern[$CellContext`x, Blank[]]] := Part[ Reap[ Sow[1, $CellContext`x], Blank[], #& ], 2], $CellContext`solutions = {{{1, 1}, {1, 3}, {1, 5}, {2, 2}, {2, 3}, {2, 4}, {3, 1}, {3, 3}, {3, 5}}, {{1, 1}, {1, 2}, {1, 4}, {1, 7}, {2, 2}, {3, 3}, {4, 4}, {5, 2}, {6, 2}, {7, 1}}, {{1, 2}, {1, 7}, {2, 2}, {2, 4}, {3, 7}, {3, 9}, {4, 1}, {4, 6}, {5, 1}, {5, 9}, {6, 3}, { 6, 5}, {7, 6}, {7, 8}, {8, 3}, {8, 8}, {9, 4}, {9, 5}}}, $CellContext`ReturnLines[ Pattern[$CellContext`ptList, Blank[]]] := Select[ Map[Union[ Flatten[ Last[#], 1]]& , Map[Transpose, SplitBy[ Sort[ Map[{ $CellContext`Liner[#], #}& , Subsets[ Union[$CellContext`ptList], {2}]]], First]]], Length[#] > 2& ], $CellContext`Liner[{ Pattern[$CellContext`pt1, Blank[]], Pattern[$CellContext`pt2, Blank[]]}] := Simplify[Det[{{$CellContext`x, $CellContext`y, 1}, { First[$CellContext`pt1], Last[$CellContext`pt1], 1}, { First[$CellContext`pt2], Last[$CellContext`pt2], 1}}]/Apply[GCD, Flatten[ CoefficientList[ Det[{{$CellContext`x, $CellContext`y, 1}, { First[$CellContext`pt1], Last[$CellContext`pt1], 1}, { First[$CellContext`pt2], Last[$CellContext`pt2], 1}}], {$CellContext`x, $CellContext`y}]]]], Attributes[PlotRange] = {ReadProtected}}; Typeset`initDone$$ = True), SynchronousInitialization->True, UnsavedVariables:>{Typeset`initDone$$}, UntrackedVariables:>{Typeset`size$$}], "Manipulate", Deployed->True, StripOnInput->False], Manipulate`InterpretManipulate[1]]], "Output", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{3.7607656291207657`*^9}, CellID->30746884] }, {6}]]