(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 6.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 4822, 142] NotebookOptionsPosition[ 4326, 122] NotebookOutlinePosition[ 4687, 138] CellTagsIndexPosition[ 4644, 135] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[TextData[{ StyleBox["11/21/08: Mathematica", FontSlant->"Italic"], " implementations of recursive Towers of Hanoi algorithm and recursive \ Euclidean (gcd) algorithm." }], "Text", CellChangeTimes->{{3.436108442744082*^9, 3.436108473277286*^9}, { 3.4361089611045246`*^9, 3.436108973870885*^9}, {3.43610937503374*^9, 3.436109380440267*^9}, {3.4362704461967225`*^9, 3.436270446462366*^9}}, FontSize->14], Cell[BoxData[ RowBox[{ RowBox[{"Hanoi", "[", RowBox[{ "n_", ",", " ", "start_", ",", " ", "finish_", ",", " ", "extra_"}], "]"}], ":=", " ", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"n", ">", "0"}], ",", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"Hanoi", "[", RowBox[{ RowBox[{"n", "-", "1"}], ",", " ", "start", ",", " ", "extra", ",", " ", "finish"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{ "\"\\"", ",", " ", "start", ",", " ", "\"\< to \>\"", ",", " ", "finish"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Hanoi", "[", RowBox[{ RowBox[{"n", "-", "1"}], ",", "extra", ",", " ", "finish", ",", " ", "start"}], "]"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "}"}]}]], "Input", CellChangeTimes->{{3.436108607895276*^9, 3.436108789813168*^9}, { 3.436108835191022*^9, 3.4361088451134686`*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"Hanoi", "[", RowBox[{ "3", ",", " ", "\"\\"", ",", " ", "\"\\"", " ", ",", "\"\\""}], "]"}], ";"}]], "Input", CellChangeTimes->{{3.4361087982512083`*^9, 3.436108811283292*^9}, 3.4361088499262457`*^9, {3.436108906335745*^9, 3.436108915086249*^9}, 3.436109531619882*^9, 3.436109592545223*^9}], Cell[BoxData[ RowBox[{ RowBox[{"gcdp", "[", RowBox[{"a_", ",", " ", "b_"}], "]"}], ":=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"{", RowBox[{"a", ",", "b"}], "}"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"If", " ", "[", RowBox[{ RowBox[{"b", "\[Equal]", "0"}], ",", " ", "a", ",", RowBox[{"gcdp", "[", RowBox[{"b", ",", " ", RowBox[{"Mod", "[", RowBox[{"a", ",", " ", "b"}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "}"}]}]], "Input", CellChangeTimes->{{3.4361089782617626`*^9, 3.436109058563263*^9}, { 3.436109090518228*^9, 3.4361091320518703`*^9}, 3.4361092062592697`*^9, 3.4361093411882577`*^9}], Cell[BoxData[ RowBox[{ RowBox[{"gcd", "[", RowBox[{"a_", ",", " ", "b_"}], "]"}], ":=", RowBox[{"If", " ", "[", RowBox[{ RowBox[{"b", "\[Equal]", "0"}], ",", " ", "a", ",", RowBox[{"gcd", "[", RowBox[{"b", ",", " ", RowBox[{"Mod", "[", RowBox[{"a", ",", " ", "b"}], "]"}]}], "]"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.4361089782617626`*^9, 3.436109058563263*^9}, { 3.436109090518228*^9, 3.4361091320518703`*^9}, 3.4361092062592697`*^9, { 3.4361092378704653`*^9, 3.4361092485585155`*^9}}], Cell[BoxData[ RowBox[{"gcd", "[", RowBox[{"248", ",", " ", "164"}], "]"}]], "Input", CellChangeTimes->{{3.4361092625123544`*^9, 3.4361092847634935`*^9}, { 3.43610940725414*^9, 3.436109425739461*^9}, {3.436270400068228*^9, 3.4362704094752007`*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"gcdp", "[", RowBox[{"248", ",", " ", "164"}], "]"}], ";"}]], "Input", CellChangeTimes->{{3.436109063141651*^9, 3.4361090690794935`*^9}, { 3.436109181476592*^9, 3.4361092117908382`*^9}, {3.436109297826662*^9, 3.4361093080146837`*^9}, 3.436109437474437*^9, 3.4362704176477027`*^9}] }, WindowSize->{611, 538}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, ShowSelection->True, FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (April 20, 2007)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[568, 21, 416, 9, 49, "Text"], Cell[987, 32, 1095, 27, 172, "Input"], Cell[2085, 61, 357, 8, 31, "Input"], Cell[2445, 71, 741, 19, 92, "Input"], Cell[3189, 92, 544, 13, 31, "Input"], Cell[3736, 107, 257, 5, 31, "Input"], Cell[3996, 114, 326, 6, 31, "Input"] } ] *) (* End of internal cache information *)