Cell[CellGroupData[{Cell[BoxData[ RowBox[{"Manipulate", "[", " ", RowBox[{ RowBox[{"Module", "[", RowBox[{ RowBox[{"{", "q", "}"}], ",", " ", RowBox[{ RowBox[{"q", "=", RowBox[{"Map", "[", " ", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"EvenQ", "[", RowBox[{"Total", "@", "#"}], "]"}], ",", "#", ",", RowBox[{"Reverse", "@", "#"}]}], "]"}], "&"}], ",", " ", RowBox[{"Sort", "[", " ", RowBox[{ RowBox[{"Flatten", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{"x", ",", "y"}], "}"}], ",", RowBox[{"{", RowBox[{"x", ",", "20"}], "}"}], ",", RowBox[{"{", RowBox[{"y", ",", "20"}], "}"}]}], "]"}], ",", "1"}], "]"}], ",", " ", RowBox[{ RowBox[{ RowBox[{ RowBox[{"#1", "[", RowBox[{"[", "1", "]"}], "]"}], "+", RowBox[{"#1", "[", RowBox[{"[", "2", "]"}], "]"}]}], "<", RowBox[{ RowBox[{"#2", "[", RowBox[{"[", "1", "]"}], "]"}], "+", RowBox[{"#2", "[", RowBox[{"[", "2", "]"}], "]"}]}]}], " ", "&"}]}], " ", "]"}]}], " ", "]"}]}], ";", " ", RowBox[{"Pane", "[", " ", RowBox[{ RowBox[{"Graphics", "[", RowBox[{ RowBox[{"{", " ", RowBox[{ RowBox[{"Style", "[", RowBox[{ RowBox[{"Text", "[", RowBox[{ RowBox[{"TraditionalForm", "@", RowBox[{"q", "[", RowBox[{"[", "d", "]"}], "]"}]}], " ", ",", RowBox[{ RowBox[{"q", "[", RowBox[{"[", "d", "]"}], "]"}], "+", RowBox[{".45", RowBox[{"{", RowBox[{"1", ",", ".5"}], "}"}]}]}]}], "]"}], ",", "Medium"}], "]"}], ",", " ", RowBox[{"RGBColor", "[", RowBox[{".1", ",", ".3", ",", ".77"}], "]"}], ",", " ", RowBox[{"If", "[", RowBox[{ RowBox[{"d", "===", "165"}], ",", RowBox[{"Style", "[", RowBox[{ RowBox[{"Text", "[", RowBox[{"\[AscendingEllipsis]", ",", RowBox[{ RowBox[{"{", RowBox[{"10", ",", "10"}], "}"}], "+", RowBox[{".45", RowBox[{"{", RowBox[{"1", ",", ".5"}], "}"}]}]}]}], "]"}], ",", "Large"}], "]"}], ",", RowBox[{"{", "}"}]}], "]"}], ",", " ", RowBox[{"Arrowheads", "[", "Medium", "]"}], ",", RowBox[{"Map", "[", RowBox[{"Arrow", ",", RowBox[{ RowBox[{ RowBox[{"Transpose", "[", RowBox[{"{", RowBox[{ RowBox[{"Most", "@", "#"}], ",", RowBox[{"Rest", "@", "#"}]}], "}"}], "]"}], "&"}], "@", RowBox[{"Take", "[", RowBox[{"q", ",", "d"}], "]"}]}]}], "]"}]}], " ", "}"}], ",", " ", RowBox[{"PlotRange", "->", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{".5", ",", "11"}], "}"}], ",", RowBox[{"{", RowBox[{".5", ",", "11"}], "}"}]}], "}"}]}], ",", " ", RowBox[{"ImageSize", "->", RowBox[{"{", RowBox[{"350", ",", "325"}], "}"}]}]}], " ", "]"}], ",", " ", RowBox[{"ImageSize", "->", RowBox[{"{", RowBox[{"350", ",", "325"}], "}"}]}]}], " ", "]"}]}]}], "]"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"d", ",", "10", ",", "\"\\""}], "}"}], ",", "1", ",", "165", ",", "1", ",", RowBox[{"Appearance", "->", "\"\\""}]}], "}"}]}], " ", "]"}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{ 3.35696210375764*^9, 3.4040799050632973`*^9, { 3.4040799517357693`*^9, 3.4040800153459587`*^9}, { 3.4040917478785477`*^9, 3.404091830785859*^9}, { 3.404093785326502*^9, 3.404093789920311*^9}, {3.404093837499045*^9, 3.4040938472804203`*^9}, {3.4040938870934296`*^9, 3.4040938933278847`*^9}, 3.760726560934395*^9}], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`d$$ = 120, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{{ Hold[$CellContext`d$$], 120, "step"}, 1, 165, 1}}, Typeset`size$$ = {350., {160., 165.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = True, $CellContext`d$203987$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`d$$ = 120}, "ControllerVariables" :> { Hold[$CellContext`d$$, $CellContext`d$203987$$, 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" :> Module[{$CellContext`q$}, $CellContext`q$ = Map[If[ EvenQ[ Total[#]], #, Reverse[#]]& , Sort[ Flatten[ Table[{$CellContext`x, $CellContext`y}, {$CellContext`x, 20}, {$CellContext`y, 20}], 1], Part[#, 1] + Part[#, 2] < Part[#2, 1] + Part[#2, 2]& ]]; Pane[ Graphics[{ Style[ Text[ TraditionalForm[ Part[$CellContext`q$, $CellContext`d$$]], Part[$CellContext`q$, $CellContext`d$$] + 0.45 {1, 0.5}], Medium], RGBColor[0.1, 0.3, 0.77], If[$CellContext`d$$ === 165, Style[ Text[$CellContext`\[AscendingEllipsis], {10, 10} + 0.45 {1, 0.5}], Large], {}], Arrowheads[Medium], Map[Arrow, (Transpose[{ Most[#], Rest[#]}]& )[ Take[$CellContext`q$, $CellContext`d$$]]]}, PlotRange -> {{0.5, 11}, {0.5, 11}}, ImageSize -> {350, 325}], ImageSize -> {350, 325}]], "Specifications" :> {{{$CellContext`d$$, 120, "step"}, 1, 165, 1, Appearance -> "Labeled"}}, "Options" :> {}, "DefaultOptions" :> {ControllerLinking -> True}], ImageSizeCache->{395., {205., 211.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, SynchronousInitialization->True, UnsavedVariables:>{Typeset`initDone$$}, UntrackedVariables:>{Typeset`size$$}], "Manipulate", Deployed->True, StripOnInput->False], Manipulate`InterpretManipulate[1]]], "Output", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{3.760726560934661*^9}, CellID->298276814] }, {2}]]