Cell[CellGroupData[{Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"JugProblemSolution", "[", RowBox[{"n_Integer", ",", "m_Integer"}], "]"}], "/;", RowBox[{"CoprimeQ", "[", RowBox[{"n", ",", "m"}], "]"}]}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "eg", ",", "sv", ",", "lv", ",", "state", ",", "commands"}], "}"}], ",", " ", RowBox[{ RowBox[{"eg", "=", RowBox[{"Last", "[", RowBox[{"ExtendedGCD", "[", RowBox[{"n", ",", "m"}], "]"}], "]"}]}], ";", " ", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"First", "[", "eg", "]"}], ">", "0"}], ",", RowBox[{ RowBox[{"{", RowBox[{"sv", ",", "lv"}], "}"}], "=", RowBox[{"{", RowBox[{"n", ",", "m"}], "}"}]}], ",", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"sv", ",", "lv"}], "}"}], "=", RowBox[{"{", RowBox[{"m", ",", "n"}], "}"}]}], ";", RowBox[{"eg", "=", RowBox[{"Reverse", "[", "eg", "]"}]}]}]}], "]"}], ";", " ", RowBox[{"state", "=", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}], ";", " ", RowBox[{"commands", "=", RowBox[{"{", "}"}]}], ";", " ", RowBox[{"While", "[", RowBox[{ RowBox[{"eg", "=!=", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}], ",", " ", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Count", "[", RowBox[{"state", ",", "1", ",", RowBox[{"{", "1", "}"}]}], "]"}], ">", "0"}], ",", RowBox[{"Break", "[", "]"}]}], "]"}], ";", " ", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"First", "[", "eg", "]"}], ">", "0"}], "&&", RowBox[{ RowBox[{"First", "[", "state", "]"}], "==", "0"}]}], ",", " ", RowBox[{ RowBox[{"eg", "+=", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "0"}], "}"}]}], ";", RowBox[{"state", "+=", RowBox[{"{", RowBox[{"sv", ",", "0"}], "}"}]}], ";", RowBox[{"AppendTo", "[", RowBox[{"commands", ",", RowBox[{"FillJug", "[", "sv", "]"}]}], "]"}], ";", RowBox[{"Continue", "[", "]"}], ";"}]}], "]"}], ";", " ", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Last", "[", "eg", "]"}], "<", "0"}], "&&", RowBox[{ RowBox[{"Last", "[", "state", "]"}], "==", "lv"}]}], ",", " ", RowBox[{ RowBox[{"eg", "+=", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}], ";", RowBox[{"state", "+=", RowBox[{"{", RowBox[{"0", ",", RowBox[{"-", "lv"}]}], "}"}]}], ";", RowBox[{"AppendTo", "[", RowBox[{"commands", ",", RowBox[{"EmptyJug", "[", "lv", "]"}]}], "]"}], ";", RowBox[{"Continue", "[", "]"}], ";"}]}], "]"}], ";", " ", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"First", "[", "state", "]"}], ">", "0"}], ",", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"delta", "=", RowBox[{"Min", "[", RowBox[{ RowBox[{"First", "[", "state", "]"}], ",", RowBox[{"lv", "-", RowBox[{"Last", "[", "state", "]"}]}]}], "]"}]}], "}"}], ",", " ", RowBox[{ RowBox[{"state", "+=", RowBox[{"{", RowBox[{ RowBox[{"-", "delta"}], ",", RowBox[{"+", "delta"}]}], "}"}]}], ";", " ", RowBox[{"AppendTo", "[", RowBox[{"commands", ",", RowBox[{"Pour", "[", RowBox[{"delta", ",", RowBox[{"sv", "->", "lv"}]}], "]"}]}], "]"}], ";", " ", RowBox[{"Continue", "[", "]"}], ";"}]}], " ", "]"}]}], "]"}], ";", " ", RowBox[{"AppendTo", "[", RowBox[{"commands", ",", "$Failed"}], "]"}], ";", " ", RowBox[{"Break", "[", "]"}], ";"}]}], " ", "]"}], ";", " ", "commands"}]}], " ", "]"}]}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{3.759793090147492*^9}, CellID->883986246], Cell[BoxData[ RowBox[{ RowBox[{"GetCoprimeNumbers", "[", "ord_", "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"m1", ",", "m2", ",", RowBox[{"k", "=", "0"}]}], "}"}], ",", " ", RowBox[{"Catch", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"CoprimeQ", "[", RowBox[{"m1", ",", "m2"}], "]"}], ",", RowBox[{"k", "++"}]}], "]"}], ";", RowBox[{"If", "[", RowBox[{ RowBox[{"k", "==", "ord"}], ",", RowBox[{"Throw", "[", RowBox[{"{", RowBox[{"m1", ",", "m2"}], "}"}], "]"}]}], "]"}]}], " ", ",", RowBox[{"{", RowBox[{"m2", ",", "5", ",", RowBox[{"7", "*", "ord"}], ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"m1", ",", "3", ",", RowBox[{"m2", "-", "2"}], ",", "2"}], "}"}]}], "]"}], "]"}]}], " ", "]"}]}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{3.759793090147574*^9}, CellID->409489983], Cell[BoxData[ RowBox[{ RowBox[{"StateDiagram", "[", RowBox[{ RowBox[{"{", RowBox[{"sv_", ",", "lv_"}], "}"}], ",", RowBox[{"{", RowBox[{"s1_", ",", "s2_"}], "}"}]}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"scale", ",", RowBox[{"space", "=", "0.1"}]}], "}"}], ",", " ", RowBox[{ RowBox[{"scale", "=", RowBox[{ RowBox[{"Max", "[", RowBox[{"s1", ",", "s2"}], "]"}], "/", "1.5"}]}], ";", " ", RowBox[{"Graphics", "[", RowBox[{"{", RowBox[{ RowBox[{"RGBColor", "[", RowBox[{"0", ",", "0.5", ",", "0.9"}], "]"}], ",", RowBox[{"Rectangle", "[", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", RowBox[{"sv", "/", "scale"}]}], "}"}]}], "]"}], ",", RowBox[{"Rectangle", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"1", "+", "space"}], ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"2", "+", "space"}], ",", RowBox[{"lv", "/", "scale"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"Directive", "[", RowBox[{"Black", ",", "Thick"}], "]"}], ",", RowBox[{"Line", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", RowBox[{"s1", "/", "scale"}]}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", RowBox[{"s1", "/", "scale"}]}], "}"}]}], "}"}], "]"}], ",", RowBox[{"Text", "[", RowBox[{ RowBox[{"Style", "[", RowBox[{ RowBox[{"Row", "[", RowBox[{"{", RowBox[{ "sv", ",", "\"\\"", ",", "s1", ",", "\"\< gallons \>\""}], "}"}], "]"}], ",", "14", ",", "Brown", ",", "\"\\""}], "]"}], ",", RowBox[{"{", RowBox[{"0.3", ",", RowBox[{"-", "0.2"}]}], "}"}]}], "]"}], ",", RowBox[{"Line", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"1", "+", "space"}], ",", RowBox[{"s2", "/", "scale"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"1", "+", "space"}], ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"2", "+", "space"}], ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"2", "+", "space"}], ",", RowBox[{"s2", "/", "scale"}]}], "}"}]}], "}"}], "]"}], ",", RowBox[{"Text", "[", RowBox[{ RowBox[{"Style", "[", RowBox[{ RowBox[{"Row", "[", RowBox[{"{", RowBox[{ "lv", ",", "\"\\"", ",", "s2", ",", "\"\< gallons \>\""}], "}"}], "]"}], ",", "14", ",", "Brown", ",", "\"\\""}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"1.5", "+", "space"}], ",", RowBox[{"-", "0.2"}]}], "}"}]}], "]"}]}], "}"}], "]"}]}]}], " ", "]"}]}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{ 3.35696210375764*^9, {3.375658864203125*^9, 3.3756588749375*^9}, { 3.377187876671875*^9, 3.377187878390625*^9}, {3.380732979203125*^9, 3.380733013765625*^9}, 3.759793090147661*^9}, CellID->381172594], Cell[BoxData[ RowBox[{ RowBox[{"AssembleSolution", "[", RowBox[{"n_", ",", "m_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"sol", ",", "state", ",", "stateevolution"}], "}"}], ",", " ", RowBox[{ RowBox[{"sol", "=", RowBox[{"JugProblemSolution", "[", RowBox[{"n", ",", "m"}], "]"}]}], ";", " ", RowBox[{"state", "=", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}], ";", " ", RowBox[{"stateevolution", "=", RowBox[{"FoldList", "[", " ", RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", RowBox[{"s", ",", "c"}], "}"}], ",", " ", RowBox[{"Which", "[", " ", RowBox[{ RowBox[{"c", "===", RowBox[{"FillJug", "[", "n", "]"}]}], ",", RowBox[{"s", "+", RowBox[{"{", RowBox[{"n", ",", "0"}], "}"}]}], ",", " ", RowBox[{"c", "===", RowBox[{"FillJug", "[", "m", "]"}]}], ",", RowBox[{"s", "+", RowBox[{"{", RowBox[{"0", ",", "m"}], "}"}]}], ",", " ", RowBox[{"c", "===", RowBox[{"EmptyJug", "[", "n", "]"}]}], ",", RowBox[{"s", "+", RowBox[{"{", RowBox[{ RowBox[{"-", "n"}], ",", "0"}], "}"}]}], ",", " ", RowBox[{"c", "===", RowBox[{"EmptyJug", "[", "m", "]"}]}], ",", RowBox[{"s", "+", RowBox[{"{", RowBox[{"0", ",", RowBox[{"-", "m"}]}], "}"}]}], ",", " ", RowBox[{"MatchQ", "[", RowBox[{"c", ",", RowBox[{"Pour", "[", RowBox[{"_", ",", RowBox[{"n", "->", "m"}]}], "]"}]}], "]"}], ",", RowBox[{"s", "+", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"delta", "=", RowBox[{"Extract", "[", RowBox[{"c", ",", RowBox[{"{", "1", "}"}]}], "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "delta"}], ",", "delta"}], "}"}]}], "]"}]}], ",", " ", RowBox[{"MatchQ", "[", RowBox[{"c", ",", RowBox[{"Pour", "[", RowBox[{"_", ",", RowBox[{"m", "->", "n"}]}], "]"}]}], "]"}], ",", RowBox[{"s", "+", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"delta", "=", RowBox[{"Extract", "[", RowBox[{"c", ",", RowBox[{"{", "1", "}"}]}], "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"delta", ",", RowBox[{"-", "delta"}]}], "}"}]}], "]"}]}]}], "]"}]}], " ", "]"}], ",", "state", ",", "sol"}], "]"}]}], ";", " ", RowBox[{"Style", "[", RowBox[{ RowBox[{"Pane", "[", RowBox[{ RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"li", "=", RowBox[{ RowBox[{ RowBox[{"StateDiagram", "[", RowBox[{"#", ",", RowBox[{"{", RowBox[{"n", ",", "m"}], "}"}]}], "]"}], "&"}], "/@", " ", RowBox[{"Rest", "[", "stateevolution", "]"}]}]}], "}"}], ",", " ", RowBox[{"Grid", "[", RowBox[{ RowBox[{"Partition", "[", RowBox[{ RowBox[{"PadRight", "[", RowBox[{"li", ",", RowBox[{"3", RowBox[{"Ceiling", "[", RowBox[{ RowBox[{"Length", "[", "li", "]"}], "/", "3"}], "]"}]}], ",", "\"\< \>\""}], "]"}], ",", "3"}], "]"}], ",", RowBox[{"Spacings", "->", RowBox[{"{", RowBox[{"1.0", ",", "0.2"}], "}"}]}], ",", RowBox[{"Dividers", "->", "Center"}]}], "]"}]}], "]"}], ",", "580"}], "]"}], ",", "\"\\"", ",", "12"}], "]"}]}]}], " ", "]"}]}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{ 3.35696210375764*^9, {3.3747599627825603`*^9, 3.374760005407287*^9}, {3.374760044953909*^9, 3.3747600651725297`*^9}, {3.37476612840625*^9, 3.3747661326875*^9}, {3.37476778068565*^9, 3.3747678124979467`*^9}, {3.3747678536383085`*^9, 3.3747678623257523`*^9}, {3.3747695078464713`*^9, 3.3747695142214303`*^9}, {3.374771454921875*^9, 3.3747714969375*^9}, {3.37477152890625*^9, 3.374771529421875*^9}, { 3.374774974734375*^9, 3.374775050453125*^9}, 3.374775092515625*^9, {3.374775131296875*^9, 3.374775242046875*^9}, {3.374775531421875*^9, 3.37477553228125*^9}, {3.375658810484375*^9, 3.375658821296875*^9}, {3.378221954890189*^9, 3.37822197693631*^9}, 3.759793090147749*^9}, CellID->323314766], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{ "JugProblemSolution", ";", "StateDiagram", ";", "FillJug", ";", "EmptyJug", ";", "Pour", ";", RowBox[{"Style", "[", RowBox[{ RowBox[{"Block", "[", RowBox[{ RowBox[{"{", RowBox[{"num", "=", RowBox[{"GetCoprimeNumbers", "[", "u", "]"}]}], "}"}], ",", RowBox[{"(", RowBox[{"AssembleSolution", "@@", "num"}], ")"}]}], "]"}], ",", "\"\\"", ",", "12"}], "]"}]}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"u", ",", "2", ",", "\"\\""}], "}"}], ",", "1", ",", "9", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"u", ",", "2"}], "}"}], ",", "1", ",", "4", ",", "1", ",", RowBox[{"ControlType", "->", "None"}]}], "}"}], ",", RowBox[{"SaveDefinitions", "->", "True"}], ",", RowBox[{"TrackedSymbols", "->", RowBox[{"{", "u", "}"}]}], ",", RowBox[{"AutorunSequencing", "->", RowBox[{"{", "2", "}"}]}]}], "]"}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{ 3.35696210375764*^9, {3.3747261354466863`*^9, 3.374726143149762*^9}, {3.37473229967286*^9, 3.3747323529381437`*^9}, {3.3747327222795305`*^9, 3.374732745873129*^9}, {3.374732777263553*^9, 3.3747327800447855`*^9}, {3.3747335227119074`*^9, 3.374733543711773*^9}, {3.374734251504118*^9, 3.3747342759727116`*^9}, {3.3747349551402397`*^9, 3.374734959655836*^9}, {3.374735481839994*^9, 3.3747354823712406`*^9}, 3.3747359856180196`*^9, { 3.3747360378989353`*^9, 3.374736056055069*^9}, { 3.3747418751483216`*^9, 3.3747418966013093`*^9}, { 3.3747552280784874`*^9, 3.3747552467658677`*^9}, { 3.3747599272202873`*^9, 3.374759932157756*^9}, 3.374760389217331*^9, {3.374766404953125*^9, 3.37476640528125*^9}, {3.374766592328125*^9, 3.374766646265625*^9}, {3.3747682871667833`*^9, 3.3747682905105124`*^9}, {3.37565872578125*^9, 3.375658777578125*^9}, {3.3782220008560386`*^9, 3.378222001527415*^9}, {3.380732826984375*^9, 3.38073282715625*^9}, 3.759793090138051*^9}, CellID->1496021318], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`u$$ = 2, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{{ Hold[$CellContext`u$$], 2, "jug capacities"}, 1, 9, 1}, {{ Hold[$CellContext`u$$], 2}, 1, 4, 1}}, Typeset`size$$ = { 580., {139., 146.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = False, $CellContext`u$82595$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`u$$ = 2}, "ControllerVariables" :> { Hold[$CellContext`u$$, $CellContext`u$82595$$, 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" :> ($CellContext`JugProblemSolution; \ $CellContext`StateDiagram; $CellContext`FillJug; \ $CellContext`EmptyJug; $CellContext`Pour; Style[ Block[{$CellContext`num = \ $CellContext`GetCoprimeNumbers[$CellContext`u$$]}, Apply[$CellContext`AssembleSolution, $CellContext`num]], "Label", 12]), "Specifications" :> {{{$CellContext`u$$, 2, "jug capacities"}, 1, 9, 1}, {{$CellContext`u$$, 2}, 1, 4, 1, ControlType -> None}}, "Options" :> { TrackedSymbols -> {$CellContext`u$$}, AutorunSequencing -> {2}}, "DefaultOptions" :> {ControllerLinking -> True}], ImageSizeCache->{625., {185., 191.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, Initialization:>({Condition[ $CellContext`JugProblemSolution[ Pattern[$CellContext`n, Blank[Integer]], Pattern[$CellContext`m, Blank[Integer]]], CoprimeQ[$CellContext`n, $CellContext`m]] := Module[{$CellContext`eg, $CellContext`sv, $CellContext`lv, \ $CellContext`state, $CellContext`commands}, $CellContext`eg = Last[ ExtendedGCD[$CellContext`n, $CellContext`m]]; If[First[$CellContext`eg] > 0, {$CellContext`sv, $CellContext`lv} = {$CellContext`n, \ $CellContext`m}, {$CellContext`sv, $CellContext`lv} = \ {$CellContext`m, $CellContext`n}; $CellContext`eg = Reverse[$CellContext`eg]]; $CellContext`state = {0, 0}; $CellContext`commands = {}; While[$CellContext`eg =!= {0, 0}, If[Count[$CellContext`state, 1, {1}] > 0, Break[]]; If[ And[ First[$CellContext`eg] > 0, First[$CellContext`state] == 0], AddTo[$CellContext`eg, {-1, 0}]; AddTo[$CellContext`state, {$CellContext`sv, 0}]; AppendTo[$CellContext`commands, $CellContext`FillJug[$CellContext`sv]]; Continue[]; Null]; If[ And[ Last[$CellContext`eg] < 0, Last[$CellContext`state] == $CellContext`lv], AddTo[$CellContext`eg, {0, 1}]; AddTo[$CellContext`state, {0, -$CellContext`lv}]; AppendTo[$CellContext`commands, $CellContext`EmptyJug[$CellContext`lv]]; Continue[]; Null]; If[First[$CellContext`state] > 0, With[{$CellContext`delta = Min[ First[$CellContext`state], $CellContext`lv - Last[$CellContext`state]]}, AddTo[$CellContext`state, {-$CellContext`delta, Plus[$CellContext`delta]}]; AppendTo[$CellContext`commands, $CellContext`Pour[$CellContext`delta, $CellContext`sv -> \ $CellContext`lv]]; Continue[]; Null]]; AppendTo[$CellContext`commands, $Failed]; Break[]; Null]; $CellContext`commands], $CellContext`StateDiagram[{ Pattern[$CellContext`sv, Blank[]], Pattern[$CellContext`lv, Blank[]]}, { Pattern[$CellContext`s1, Blank[]], Pattern[$CellContext`s2, Blank[]]}] := Module[{$CellContext`scale, $CellContext`space = 0.1}, $CellContext`scale = Max[$CellContext`s1, $CellContext`s2]/1.5; Graphics[{ RGBColor[0, 0.5, 0.9], Rectangle[{0, 0}, { 1, $CellContext`sv/$CellContext`scale}], Rectangle[{1 + $CellContext`space, 0}, { 2 + $CellContext`space, \ $CellContext`lv/$CellContext`scale}], Directive[Black, Thick], Line[{{0, $CellContext`s1/$CellContext`scale}, {0, 0}, {1, 0}, {1, $CellContext`s1/$CellContext`scale}}], Text[ Style[ Row[{$CellContext`sv, "/", $CellContext`s1, " gallons "}], 14, Brown, "Label"], {0.3, -0.2}], Line[{{1 + $CellContext`space, \ $CellContext`s2/$CellContext`scale}, {1 + $CellContext`space, 0}, { 2 + $CellContext`space, 0}, { 2 + $CellContext`space, \ $CellContext`s2/$CellContext`scale}}], Text[ Style[ Row[{$CellContext`lv, "/", $CellContext`s2, " gallons "}], 14, Brown, "Label"], { 1.5 + $CellContext`space, -0.2}]}]], \ $CellContext`GetCoprimeNumbers[ Pattern[$CellContext`ord, Blank[]]] := Module[{$CellContext`m1, $CellContext`m2, $CellContext`k = 0}, Catch[ Table[If[ CoprimeQ[$CellContext`m1, $CellContext`m2], Increment[$CellContext`k]]; If[$CellContext`k == $CellContext`ord, Throw[{$CellContext`m1, $CellContext`m2}]], \ {$CellContext`m2, 5, 7 $CellContext`ord, 2}, {$CellContext`m1, 3, $CellContext`m2 - 2, 2}]]], $CellContext`AssembleSolution[ Pattern[$CellContext`n, Blank[]], Pattern[$CellContext`m, Blank[]]] := Module[{$CellContext`sol, $CellContext`state, \ $CellContext`stateevolution}, $CellContext`sol = \ $CellContext`JugProblemSolution[$CellContext`n, $CellContext`m]; \ $CellContext`state = {0, 0}; $CellContext`stateevolution = FoldList[ Function[{$CellContext`s, $CellContext`c}, Which[$CellContext`c === \ $CellContext`FillJug[$CellContext`n], $CellContext`s + \ {$CellContext`n, 0}, $CellContext`c === \ $CellContext`FillJug[$CellContext`m], $CellContext`s + { 0, $CellContext`m}, $CellContext`c === \ $CellContext`EmptyJug[$CellContext`n], $CellContext`s + \ {-$CellContext`n, 0}, $CellContext`c === \ $CellContext`EmptyJug[$CellContext`m], $CellContext`s + { 0, -$CellContext`m}, MatchQ[$CellContext`c, $CellContext`Pour[ Blank[], $CellContext`n -> $CellContext`m]], \ $CellContext`s + With[{$CellContext`delta = Extract[$CellContext`c, { 1}]}, {-$CellContext`delta, $CellContext`delta}], MatchQ[$CellContext`c, $CellContext`Pour[ Blank[], $CellContext`m -> $CellContext`n]], \ $CellContext`s + With[{$CellContext`delta = Extract[$CellContext`c, { 1}]}, {$CellContext`delta, \ -$CellContext`delta}]]], $CellContext`state, $CellContext`sol]; Style[ Pane[ With[{$CellContext`li = Map[$CellContext`StateDiagram[#, {$CellContext`n, \ $CellContext`m}]& , Rest[$CellContext`stateevolution]]}, Grid[ Partition[ PadRight[$CellContext`li, 3 Ceiling[Length[$CellContext`li]/3], " "], 3], Spacings -> {1., 0.2}, Dividers -> Center]], 580], "Label", 12]]}; 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.759793090138442*^9}, CellID->373945829] }, {6}]]