Cell[CellGroupData[{Cell[BoxData[ RowBox[{ RowBox[{"dif", "[", "n_", "]"}], ":=", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"Abs", "[", RowBox[{"N", "[", RowBox[{ RowBox[{"n", "[", RowBox[{"[", "i", "]"}], "]"}], "-", RowBox[{"n", "[", RowBox[{"[", RowBox[{"i", "-", "1"}], "]"}], "]"}]}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "2", ",", "4"}], "}"}]}], "]"}], "~", "Join", "~", RowBox[{"{", RowBox[{"Abs", "[", RowBox[{"N", "[", RowBox[{ RowBox[{"n", "[", RowBox[{"[", "4", "]"}], "]"}], "-", RowBox[{"n", "[", RowBox[{"[", "1", "]"}], "]"}]}], "]"}], "]"}], "}"}]}]}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, InitializationCell->True, CellChangeTimes->{{3.412865756098936*^9, 3.412865933401678*^9}, { 3.412867180573716*^9, 3.412867230926197*^9}, 3.760818899464003*^9}, CellID->314619119], Cell[BoxData[ RowBox[{ RowBox[{"half", "[", "pt_", "]"}], ":=", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"pt", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"pt", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}]}], ")"}], "/", "2"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{ RowBox[{"Length", "[", "pt", "]"}], "-", "1"}]}], "}"}]}], "]"}], "~", "Join", "~", RowBox[{"{", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"pt", "[", RowBox[{"[", "1", "]"}], "]"}], "+", RowBox[{"pt", "[", RowBox[{"[", RowBox[{"Length", "[", "pt", "]"}], "]"}], "]"}]}], ")"}], "/", "2"}], "}"}]}]}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, InitializationCell->True, CellChangeTimes->{{3.412889870514366*^9, 3.412890051621003*^9}, { 3.4128902158346443`*^9, 3.412890219023664*^9}, { 3.412890249393056*^9, 3.412890250682252*^9}, { 3.4128905893637743`*^9, 3.412890619295945*^9}, 3.412890692019032*^9, 3.412890754681581*^9, {3.412890941419388*^9, 3.412890980167408*^9}, 3.760818899464143*^9}, CellID->698794119], Cell[BoxData[ RowBox[{ RowBox[{"test", "[", "n_", "]"}], ":=", RowBox[{"Block", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"i", "=", "0"}], ",", RowBox[{"b", "=", "n"}]}], "}"}], ",", RowBox[{ RowBox[{"While", "[", RowBox[{ RowBox[{"b", "!=", RowBox[{"{", RowBox[{"0", ",", "0", ",", "0", ",", "0"}], "}"}]}], ",", RowBox[{ RowBox[{"b", "=", RowBox[{"Nest", "[", RowBox[{"dif", ",", "n", ",", "i"}], "]"}]}], ";", RowBox[{"i", "++"}]}]}], "]"}], ";", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{"Nest", "[", RowBox[{"dif", ",", "n", ",", "p"}], "]"}], ",", RowBox[{"{", RowBox[{"p", ",", "0", ",", RowBox[{"i", "-", "1"}]}], "}"}]}], "]"}]}]}], "]"}]}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, InitializationCell->True, CellChangeTimes->{{3.4130551306954317`*^9, 3.413055193287899*^9}, 3.413397057576292*^9, 3.466804989910777*^9, 3.7608188994642878`*^9}, CellID->1668393798], Cell[BoxData[ RowBox[{"Manipulate", "[", " ", RowBox[{ RowBox[{ RowBox[{"nums", "=", RowBox[{"test", "[", RowBox[{"{", RowBox[{"j", ",", "k", ",", "l", ",", "m"}], "}"}], "]"}]}], ";", RowBox[{"p", "=", RowBox[{"Length", "[", "nums", "]"}]}], ";", RowBox[{"a", "=", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}], "}"}]}], ";", RowBox[{"halfs", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Nest", "[", RowBox[{"half", ",", "a", ",", "i"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "0", ",", "p"}], "}"}]}], "]"}]}], ";", " ", RowBox[{"halfsplus", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"halfs", "[", RowBox[{"[", "i", "]"}], "]"}], "~", "Join", "~", RowBox[{"{", RowBox[{"halfs", "[", RowBox[{"[", RowBox[{"i", ",", "1"}], "]"}], "]"}], "}"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "p"}], "}"}]}], "]"}]}], ";", RowBox[{"halflines", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Line", "[", RowBox[{"halfsplus", "[", RowBox[{"[", "i", "]"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "p"}], "}"}]}], "]"}]}], ";", " ", RowBox[{"colors", "=", RowBox[{"{", RowBox[{"Blue", ",", "Red", ",", "Green"}], "}"}]}], ";", RowBox[{"numGrf", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Text", "[", RowBox[{ RowBox[{"Style", "[", RowBox[{ RowBox[{"ToString", "[", RowBox[{"nums", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], "]"}], ",", RowBox[{"colors", "[", RowBox[{"[", RowBox[{ RowBox[{"Mod", "[", RowBox[{"i", ",", "3"}], "]"}], "+", "1"}], "]"}], "]"}], ",", RowBox[{"FontSize", "->", RowBox[{"(", RowBox[{"16", "-", "i"}], ")"}]}]}], "]"}], ",", RowBox[{"1.02", RowBox[{"halfs", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}]}]}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", "4"}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "p"}], "}"}]}], "]"}]}], ";", " ", RowBox[{"Graphics", "[", RowBox[{ RowBox[{"{", RowBox[{"numGrf", ",", "halflines"}], "}"}], ",", RowBox[{"PlotLabel", "->", RowBox[{"\"\\"", "<>", " ", RowBox[{"ToString", "[", RowBox[{"p", "-", "1"}], "]"}], "<>", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"p", "-", "1"}], "===", "1"}], ",", "\"\< step.\>\"", ",", "\"\< steps.\>\""}], "]"}]}]}], ",", RowBox[{"ImageSize", "->", RowBox[{"{", RowBox[{"400", ",", "400"}], "}"}]}], ",", RowBox[{"ImagePadding", "->", "20"}]}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{"j", ",", "1", ",", "200", ",", "1", ",", RowBox[{"Appearance", "->", "\"\\""}], ",", RowBox[{"ImageSize", "->", "Small"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{"k", ",", "1", ",", "200", ",", "1", ",", RowBox[{"Appearance", "->", "\"\\""}], ",", RowBox[{"ImageSize", "->", "Small"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{"l", ",", "1", ",", "200", ",", "1", ",", RowBox[{"Appearance", "->", "\"\\""}], ",", RowBox[{"ImageSize", "->", "Small"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{"m", ",", "1", ",", "200", ",", "1", ",", RowBox[{"Appearance", "->", "\"\\""}], ",", RowBox[{"ImageSize", "->", "Small"}]}], "}"}], ",", " ", RowBox[{"ControlPlacement", "->", "Left"}], ",", " ", RowBox[{"SaveDefinitions", "->", "True"}], ",", RowBox[{"TrackedSymbols", "->", "True"}]}], "]"}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{{3.412866118351802*^9, 3.412866170713799*^9}, { 3.412866282266492*^9, 3.4128662851541567`*^9}, 3.4128670195915737`*^9, {3.412867566724626*^9, 3.41286756997442*^9}, {3.412867652108672*^9, 3.412867709062685*^9}, {3.412867741749251*^9, 3.412867766244705*^9}, {3.4128678174851503`*^9, 3.412867862314217*^9}, {3.4128687735297117`*^9, 3.412868784056837*^9}, {3.4128688336995077`*^9, 3.412868845724997*^9}, {3.412985982586985*^9, 3.4129859959563932`*^9}, {3.4129860435416737`*^9, 3.412986158758883*^9}, {3.4129861969895287`*^9, 3.4129862246913633`*^9}, {3.412986303076868*^9, 3.412986304433331*^9}, {3.4130557426554537`*^9, 3.41305576626939*^9}, {3.413055817290309*^9, 3.413055873608053*^9}, {3.41305591843257*^9, 3.413055956762458*^9}, 3.413055987171336*^9, {3.413056178767269*^9, 3.41305618094058*^9}, {3.413067606209053*^9, 3.413067609950972*^9}, {3.413067905226286*^9, 3.413067978479561*^9}, 3.413068819185223*^9, 3.413068879171749*^9, 3.413068923010067*^9, {3.413287028467347*^9, 3.4132870301585293`*^9}, {3.413287875953665*^9, 3.4132879142197447`*^9}, 3.4134157400300426`*^9, { 3.466378670050267*^9, 3.466378670911867*^9}, { 3.4665274737983704`*^9, 3.4665275064742637`*^9}, { 3.466805031567027*^9, 3.466805214520152*^9}, { 3.4669505060887575`*^9, 3.4669505117363224`*^9}, 3.760818899454389*^9}, CellID->1446681052], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`j$$ = 1, $CellContext`k$$ = 1, $CellContext`l$$ = 1, $CellContext`m$$ = 1, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{ Hold[$CellContext`j$$], 1, 200, 1}, { Hold[$CellContext`k$$], 1, 200, 1}, { Hold[$CellContext`l$$], 1, 200, 1}, { Hold[$CellContext`m$$], 1, 200, 1}}, Typeset`size$$ = { 400., {198., 202.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = False, $CellContext`j$1033759$$ = 0, $CellContext`k$1033760$$ = 0, $CellContext`l$1033761$$ = 0, $CellContext`m$1033762$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`j$$ = 1, $CellContext`k$$ = 1, $CellContext`l$$ = 1, $CellContext`m$$ = 1}, "ControllerVariables" :> { Hold[$CellContext`j$$, $CellContext`j$1033759$$, 0], Hold[$CellContext`k$$, $CellContext`k$1033760$$, 0], Hold[$CellContext`l$$, $CellContext`l$1033761$$, 0], Hold[$CellContext`m$$, $CellContext`m$1033762$$, 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`nums = \ $CellContext`test[{$CellContext`j$$, $CellContext`k$$, \ $CellContext`l$$, $CellContext`m$$}]; $CellContext`p = Length[$CellContext`nums]; $CellContext`a = {{0, 0}, {1, 0}, { 1, 1}, {0, 1}}; $CellContext`halfs = Table[ Nest[$CellContext`half, $CellContext`a, $CellContext`i], \ {$CellContext`i, 0, $CellContext`p}]; $CellContext`halfsplus = Table[ Join[ Part[$CellContext`halfs, $CellContext`i], { Part[$CellContext`halfs, $CellContext`i, 1]}], {$CellContext`i, 1, $CellContext`p}]; $CellContext`halflines = Table[ Line[ Part[$CellContext`halfsplus, $CellContext`i]], \ {$CellContext`i, 1, $CellContext`p}]; $CellContext`colors = { Blue, Red, Green}; $CellContext`numGrf = Table[ Text[ Style[ ToString[ Part[$CellContext`nums, $CellContext`i, \ $CellContext`j$$]], Part[$CellContext`colors, Mod[$CellContext`i, 3] + 1], FontSize -> 16 - $CellContext`i], 1.02 Part[$CellContext`halfs, $CellContext`i, \ $CellContext`j$$]], {$CellContext`j$$, 1, 4}, {$CellContext`i, 1, $CellContext`p}]; Graphics[{$CellContext`numGrf, $CellContext`halflines}, PlotLabel -> StringJoin["The longevity is ", ToString[$CellContext`p - 1], If[$CellContext`p - 1 === 1, " step.", " steps."]], ImageSize -> {400, 400}, ImagePadding -> 20]), "Specifications" :> {{$CellContext`j$$, 1, 200, 1, Appearance -> "Labeled", ImageSize -> Small}, {$CellContext`k$$, 1, 200, 1, Appearance -> "Labeled", ImageSize -> Small}, {$CellContext`l$$, 1, 200, 1, Appearance -> "Labeled", ImageSize -> Small}, {$CellContext`m$$, 1, 200, 1, Appearance -> "Labeled", ImageSize -> Small}}, "Options" :> {ControlPlacement -> Left, TrackedSymbols -> True}, "DefaultOptions" :> {ControllerLinking -> True}], ImageSizeCache->{610., {227., 233.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, Initialization:>({$CellContext`nums = {{1, 1, 1, 1}, {0., 0., 0., 0.}}, $CellContext`test[ Pattern[$CellContext`n, Blank[]]] := Block[{$CellContext`i = 0, $CellContext`b = $CellContext`n}, While[$CellContext`b != {0, 0, 0, 0}, $CellContext`b = Nest[$CellContext`dif, $CellContext`n, $CellContext`i]; Increment[$CellContext`i]]; Table[ Nest[$CellContext`dif, $CellContext`n, $CellContext`p], \ {$CellContext`p, 0, $CellContext`i - 1}]], $CellContext`dif[ Pattern[$CellContext`n, Blank[]]] := Join[ Table[ Abs[ N[ Part[$CellContext`n, $CellContext`i] - Part[$CellContext`n, $CellContext`i - 1]]], {$CellContext`i, 2, 4}], { Abs[ N[ Part[$CellContext`n, 4] - Part[$CellContext`n, 1]]]}], $CellContext`p = 2, $CellContext`a = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}, $CellContext`halfs = {{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, {{1/2, 0}, {1, 1/2}, {1/2, 1}, {0, 1/2}}, {{3/4, 1/4}, { 3/4, 3/4}, {1/4, 3/4}, {1/4, 1/4}}}, $CellContext`half[ Pattern[$CellContext`pt, Blank[]]] := Join[ Table[(Part[$CellContext`pt, $CellContext`i] + Part[$CellContext`pt, $CellContext`i + 1])/ 2, {$CellContext`i, 1, Length[$CellContext`pt] - 1}], {( Part[$CellContext`pt, 1] + Part[$CellContext`pt, Length[$CellContext`pt]])/ 2}], $CellContext`halfsplus = {{{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}, {{1/2, 0}, {1, 1/2}, {1/2, 1}, {0, 1/2}, { 1/2, 0}}}, $CellContext`halflines = { Line[{{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}], Line[{{1/2, 0}, {1, 1/2}, {1/2, 1}, {0, 1/2}, { 1/2, 0}}]}, $CellContext`colors = { RGBColor[0, 0, 1], RGBColor[1, 0, 0], RGBColor[0, 1, 0]}, $CellContext`numGrf = {{ Text[ Style["1", RGBColor[1, 0, 0], FontSize -> 15], {0, 0}], Text[ Style["0.", RGBColor[0, 1, 0], FontSize -> 14], {0.51, 0}]}, { Text[ Style["1", RGBColor[1, 0, 0], FontSize -> 15], {1.02, 0}], Text[ Style["0.", RGBColor[0, 1, 0], FontSize -> 14], {1.02, 0.51}]}, { Text[ Style["1", RGBColor[1, 0, 0], FontSize -> 15], {1.02, 1.02}], Text[ Style["0.", RGBColor[0, 1, 0], FontSize -> 14], {0.51, 1.02}]}, { Text[ Style["1", RGBColor[1, 0, 0], FontSize -> 15], {0, 1.02}], Text[ Style["0.", RGBColor[0, 1, 0], FontSize -> 14], {0, 0.51}]}}}; 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.76081889945466*^9}, CellID->704825415] }, {5}]]