(* 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[ 37520, 957] NotebookOptionsPosition[ 33509, 831] NotebookOutlinePosition[ 35099, 881] CellTagsIndexPosition[ 34779, 869] WindowFrame->Normal ContainsDynamic->True *) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Leads in Coin Tossing", "DemoTitle", CellChangeTimes->{ 3.35696210375764*^9, {3.38374627640625*^9, 3.383746282640625*^9}}], Cell["", "InitializationSection"], Cell[CellGroupData[{ Cell["", "ManipulateSection"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{ RowBox[{"SeedRandom", "[", "sr", "]"}], ";", "\[IndentingNewLine]", RowBox[{"y", "=", RowBox[{"Which", "[", RowBox[{ RowBox[{"n", "\[Equal]", "10"}], ",", " ", "5", ",", RowBox[{"n", "\[Equal]", "100"}], ",", "15", ",", RowBox[{"n", "\[Equal]", "1000"}], ",", " ", "50", ",", " ", RowBox[{"n", "\[Equal]", "10000"}], ",", " ", "220"}], "]"}]}], ";", RowBox[{"list", "=", RowBox[{"Accumulate", "[", RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "1"}], "}"}], ",", RowBox[{"{", "n", "}"}]}], "]"}], "]"}]}], ";", RowBox[{"ListLinePlot", "[", RowBox[{"list", ",", " ", RowBox[{"AxesOrigin", " ", "\[Rule]", " ", RowBox[{"{", RowBox[{"1", ",", " ", "0"}], "}"}]}], ",", RowBox[{"Axes", "\[Rule]", RowBox[{"{", RowBox[{"True", ",", " ", "False"}], "}"}]}], ",", " ", RowBox[{"Filling", "\[Rule]", "Axis"}], ",", " ", RowBox[{"PlotRange", " ", "\[Rule]", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", " ", "n"}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"-", "y"}], ",", " ", "y"}], "}"}]}], "}"}]}], ",", " ", RowBox[{"Ticks", " ", "\[Rule]", " ", "None"}], ",", "\[IndentingNewLine]", RowBox[{"PlotLabel", "\[Rule]", RowBox[{"Style", "[", RowBox[{ RowBox[{"Column", "[", RowBox[{"{", " ", RowBox[{"\"\\"", ",", RowBox[{"Row", "[", RowBox[{"{", RowBox[{"\"\\"", ",", RowBox[{"N", "[", RowBox[{"100", " ", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"Count", "[", " ", RowBox[{ RowBox[{"Part", "[", RowBox[{"list", ",", RowBox[{"Flatten", "[", RowBox[{ RowBox[{"Position", "[", RowBox[{"list", ",", " ", "0"}], "]"}], "-", "1"}], "]"}]}], "]"}], ",", RowBox[{"x_", "/;", RowBox[{"x", "\[GreaterEqual]", "0"}]}]}], "]"}], " ", "+", RowBox[{"Count", "[", RowBox[{"list", ",", RowBox[{"x_", "/;", RowBox[{"x", ">", "0"}]}]}], "]"}]}], ")"}], "/", RowBox[{"Length", "[", "list", "]"}]}]}], "]"}]}], " ", "}"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Row", "[", RowBox[{"{", RowBox[{"\"\\"", ",", RowBox[{"N", "[", RowBox[{"100", " ", RowBox[{ RowBox[{"(", " ", RowBox[{ RowBox[{"Count", "[", " ", RowBox[{ RowBox[{"Part", "[", RowBox[{"list", ",", RowBox[{"Flatten", "[", RowBox[{ RowBox[{"Position", "[", RowBox[{"list", ",", " ", "0"}], "]"}], "-", "1"}], "]"}]}], "]"}], ",", RowBox[{"x_", "/;", RowBox[{"x", "<=", "0"}]}]}], "]"}], "+", RowBox[{"Count", "[", RowBox[{"list", ",", RowBox[{"x_", "/;", RowBox[{"x", "<", "0"}]}]}], "]"}]}], ")"}], "/", RowBox[{"Length", "[", "list", "]"}]}]}], "]"}]}], "}"}], "]"}]}], "\[IndentingNewLine]", "}"}], "]"}], ",", "\"\\""}], "]"}]}], ",", RowBox[{"ImageSize", "\[Rule]", RowBox[{"{", RowBox[{"450", ",", "300"}], "}"}]}]}], "]"}]}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"n", ",", "10000", ",", "\"\\""}], "}"}], ",", RowBox[{"{", RowBox[{"10", ",", "100", ",", "1000", ",", "10000"}], "}"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"sr", ",", "123", ",", "\"\\""}], "}"}], ",", "1", ",", "12345", ",", "1"}], "}"}], ",", RowBox[{"TrackedSymbols", "\[RuleDelayed]", RowBox[{"{", RowBox[{"n", ",", "sr"}], "}"}]}]}], "]"}]], "Input", CellChangeTimes->{ 3.35696210375764*^9, {3.38374631040625*^9, 3.383746317328125*^9}, { 3.38374887784375*^9, 3.38374888815625*^9}, {3.383748956234375*^9, 3.38374903275*^9}, {3.384277585807664*^9, 3.384277608963321*^9}, { 3.3842777127419147`*^9, 3.384277774130968*^9}, {3.384277832816965*^9, 3.3842778526133337`*^9}, {3.384277973500291*^9, 3.384278014656026*^9}, { 3.3842780716767597`*^9, 3.3842780979603643`*^9}, {3.38429618428125*^9, 3.384296185296875*^9}}], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`n$$ = 10000, $CellContext`sr$$ = 123, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{{ Hold[$CellContext`n$$], 10000, "number of tosses"}, {10, 100, 1000, 10000}}, {{ Hold[$CellContext`sr$$], 123, "random seed"}, 1, 12345, 1}}, Typeset`size$$ = {450., {148., 152.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = True, $CellContext`n$4895$$ = 0, $CellContext`sr$4896$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`n$$ = 10000, $CellContext`sr$$ = 123}, "ControllerVariables" :> { Hold[$CellContext`n$$, $CellContext`n$4895$$, 0], Hold[$CellContext`sr$$, $CellContext`sr$4896$$, 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$$]; $CellContext`y = Which[$CellContext`n$$ == 10, 5, $CellContext`n$$ == 100, 15, $CellContext`n$$ == 1000, 50, $CellContext`n$$ == 10000, 220]; $CellContext`list = Accumulate[ RandomChoice[{-1, 1}, {$CellContext`n$$}]]; ListLinePlot[$CellContext`list, AxesOrigin -> {1, 0}, Axes -> {True, False}, Filling -> Axis, PlotRange -> {{ 0, $CellContext`n$$}, {-$CellContext`y, $CellContext`y}}, Ticks -> None, PlotLabel -> Style[ Column[{"percent of time in the lead", Row[{"heads = ", N[100 ((Count[ Part[$CellContext`list, Flatten[Position[$CellContext`list, 0] - 1]], Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x >= 0]] + Count[$CellContext`list, Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x > 0]])/ Length[$CellContext`list])]}], Row[{"tails = ", N[100 ((Count[ Part[$CellContext`list, Flatten[Position[$CellContext`list, 0] - 1]], Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x <= 0]] + Count[$CellContext`list, Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x < 0]])/ Length[$CellContext`list])]}]}], "Label"], ImageSize -> {450, 300}]), "Specifications" :> {{{$CellContext`n$$, 10000, "number of tosses"}, { 10, 100, 1000, 10000}}, {{$CellContext`sr$$, 123, "random seed"}, 1, 12345, 1}}, "Options" :> {TrackedSymbols :> {$CellContext`n$$, $CellContext`sr$$}}, "DefaultOptions" :> {ControllerLinking -> True}], ImageSizeCache->{494., {204., 209.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, SynchronousInitialization->True, UnsavedVariables:>{Typeset`initDone$$}, UntrackedVariables:>{Typeset`size$$}], "Manipulate", Deployed->True, StripOnInput->False], Manipulate`InterpretManipulate[1]]], "Output", CellID->22635471] }, {2}]] }, Open ]], Cell[CellGroupData[{ Cell["", "ManipulateCaptionSection"], Cell["\<\ Consider a game in which a fair coin is tossed repeatedly. When the \ cumulative number of heads is greater than the cumulative number of tails, \ heads is in the lead. Tails moves to the lead when the cumulative number of \ tails is greater than the cumulative number of heads. Intuition might suggest \ that with a large number of coin tosses, heads and tails would spend roughly \ equal time in the lead. In fact, it is much more likely that one side or the \ other will be lucky a high proportion of the time. When the blue line is \ above the horizontal, heads is in the lead; when it is below, tails is in the \ lead. Vary the random seed and observe how often one side or the other is in \ the lead close to 100% of the time.\ \>", "ManipulateCaption", CellChangeTimes->{ 3.35696210375764*^9, {3.38374635559375*^9, 3.383746357765625*^9}, 3.383747881210219*^9}] }, Open ]], Cell[CellGroupData[{ Cell["", "ThumbnailSection"], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`n$$ = 10000, $CellContext`sr$$ = 883, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{{ Hold[$CellContext`n$$], 10000, "number of tosses"}, {10, 100, 1000, 10000}}, {{ Hold[$CellContext`sr$$], 123, "random seed"}, 1, 12345, 1}}, Typeset`size$$ = {450., {148., 152.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = True, $CellContext`n$4950$$ = 0, $CellContext`sr$4951$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`n$$ = 10000, $CellContext`sr$$ = 123}, "ControllerVariables" :> { Hold[$CellContext`n$$, $CellContext`n$4950$$, 0], Hold[$CellContext`sr$$, $CellContext`sr$4951$$, 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$$]; $CellContext`y = Which[$CellContext`n$$ == 10, 5, $CellContext`n$$ == 100, 15, $CellContext`n$$ == 1000, 50, $CellContext`n$$ == 10000, 220]; $CellContext`list = Accumulate[ RandomChoice[{-1, 1}, {$CellContext`n$$}]]; ListLinePlot[$CellContext`list, AxesOrigin -> {1, 0}, Axes -> {True, False}, Filling -> Axis, PlotRange -> {{ 0, $CellContext`n$$}, {-$CellContext`y, $CellContext`y}}, Ticks -> None, PlotLabel -> Style[ Column[{"percent of time in the lead", Row[{"heads = ", N[100 ((Count[ Part[$CellContext`list, Flatten[Position[$CellContext`list, 0] - 1]], Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x >= 0]] + Count[$CellContext`list, Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x > 0]])/ Length[$CellContext`list])]}], Row[{"tails = ", N[100 ((Count[ Part[$CellContext`list, Flatten[Position[$CellContext`list, 0] - 1]], Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x <= 0]] + Count[$CellContext`list, Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x < 0]])/ Length[$CellContext`list])]}]}], "Label"], ImageSize -> {450, 300}]), "Specifications" :> {{{$CellContext`n$$, 10000, "number of tosses"}, { 10, 100, 1000, 10000}}, {{$CellContext`sr$$, 123, "random seed"}, 1, 12345, 1}}, "Options" :> {TrackedSymbols :> {$CellContext`n$$, $CellContext`sr$$}}, "DefaultOptions" :> {ControllerLinking -> True}], ImageSizeCache->{494., {204., 209.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, SynchronousInitialization->True, UnsavedVariables:>{Typeset`initDone$$}, UntrackedVariables:>{Typeset`size$$}], "Manipulate", Deployed->True, StripOnInput->False], Manipulate`InterpretManipulate[1]]], "Output", CellID->743974050] }, Open ]], Cell[CellGroupData[{ Cell["", "SnapshotsSection"], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`n$$ = 10, $CellContext`sr$$ = 123, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{{ Hold[$CellContext`n$$], 10, "number of tosses"}, {10, 100, 1000, 10000}}, {{ Hold[$CellContext`sr$$], 123, "random seed"}, 1, 12345, 1}}, Typeset`size$$ = {450., {148., 152.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = True, $CellContext`n$5005$$ = 0, $CellContext`sr$5006$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`n$$ = 10, $CellContext`sr$$ = 123}, "ControllerVariables" :> { Hold[$CellContext`n$$, $CellContext`n$5005$$, 0], Hold[$CellContext`sr$$, $CellContext`sr$5006$$, 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$$]; $CellContext`y = Which[$CellContext`n$$ == 10, 5, $CellContext`n$$ == 100, 15, $CellContext`n$$ == 1000, 50, $CellContext`n$$ == 10000, 220]; $CellContext`list = Accumulate[ RandomChoice[{-1, 1}, {$CellContext`n$$}]]; ListLinePlot[$CellContext`list, AxesOrigin -> {1, 0}, Axes -> {True, False}, Filling -> Axis, PlotRange -> {{ 0, $CellContext`n$$}, {-$CellContext`y, $CellContext`y}}, Ticks -> None, PlotLabel -> Style[ Column[{"percent of time in the lead", Row[{"heads = ", N[100 ((Count[ Part[$CellContext`list, Flatten[Position[$CellContext`list, 0] - 1]], Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x >= 0]] + Count[$CellContext`list, Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x > 0]])/ Length[$CellContext`list])]}], Row[{"tails = ", N[100 ((Count[ Part[$CellContext`list, Flatten[Position[$CellContext`list, 0] - 1]], Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x <= 0]] + Count[$CellContext`list, Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x < 0]])/ Length[$CellContext`list])]}]}], "Label"], ImageSize -> {450, 300}]), "Specifications" :> {{{$CellContext`n$$, 10, "number of tosses"}, {10, 100, 1000, 10000}}, {{$CellContext`sr$$, 123, "random seed"}, 1, 12345, 1}}, "Options" :> {TrackedSymbols :> {$CellContext`n$$, $CellContext`sr$$}}, "DefaultOptions" :> {ControllerLinking -> True}], ImageSizeCache->{494., {204., 209.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, SynchronousInitialization->True, UnsavedVariables:>{Typeset`initDone$$}, UntrackedVariables:>{Typeset`size$$}], "Manipulate", Deployed->True, StripOnInput->False], Manipulate`InterpretManipulate[1]]], "Output", CellID->33166934], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`n$$ = 100, $CellContext`sr$$ = 123, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{{ Hold[$CellContext`n$$], 100, "number of tosses"}, {10, 100, 1000, 10000}}, {{ Hold[$CellContext`sr$$], 123, "random seed"}, 1, 12345, 1}}, Typeset`size$$ = {450., {148., 152.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = True, $CellContext`n$5060$$ = 0, $CellContext`sr$5061$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`n$$ = 100, $CellContext`sr$$ = 123}, "ControllerVariables" :> { Hold[$CellContext`n$$, $CellContext`n$5060$$, 0], Hold[$CellContext`sr$$, $CellContext`sr$5061$$, 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$$]; $CellContext`y = Which[$CellContext`n$$ == 10, 5, $CellContext`n$$ == 100, 15, $CellContext`n$$ == 1000, 50, $CellContext`n$$ == 10000, 220]; $CellContext`list = Accumulate[ RandomChoice[{-1, 1}, {$CellContext`n$$}]]; ListLinePlot[$CellContext`list, AxesOrigin -> {1, 0}, Axes -> {True, False}, Filling -> Axis, PlotRange -> {{ 0, $CellContext`n$$}, {-$CellContext`y, $CellContext`y}}, Ticks -> None, PlotLabel -> Style[ Column[{"percent of time in the lead", Row[{"heads = ", N[100 ((Count[ Part[$CellContext`list, Flatten[Position[$CellContext`list, 0] - 1]], Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x >= 0]] + Count[$CellContext`list, Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x > 0]])/ Length[$CellContext`list])]}], Row[{"tails = ", N[100 ((Count[ Part[$CellContext`list, Flatten[Position[$CellContext`list, 0] - 1]], Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x <= 0]] + Count[$CellContext`list, Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x < 0]])/ Length[$CellContext`list])]}]}], "Label"], ImageSize -> {450, 300}]), "Specifications" :> {{{$CellContext`n$$, 100, "number of tosses"}, {10, 100, 1000, 10000}}, {{$CellContext`sr$$, 123, "random seed"}, 1, 12345, 1}}, "Options" :> {TrackedSymbols :> {$CellContext`n$$, $CellContext`sr$$}}, "DefaultOptions" :> {ControllerLinking -> True}], ImageSizeCache->{494., {204., 209.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, SynchronousInitialization->True, UnsavedVariables:>{Typeset`initDone$$}, UntrackedVariables:>{Typeset`size$$}], "Manipulate", Deployed->True, StripOnInput->False], Manipulate`InterpretManipulate[1]]], "Output", CellID->489102385], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`n$$ = 1000, $CellContext`sr$$ = 123, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{{ Hold[$CellContext`n$$], 1000, "number of tosses"}, {10, 100, 1000, 10000}}, {{ Hold[$CellContext`sr$$], 123, "random seed"}, 1, 12345, 1}}, Typeset`size$$ = {450., {148., 152.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = True, $CellContext`n$5115$$ = 0, $CellContext`sr$5116$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`n$$ = 1000, $CellContext`sr$$ = 123}, "ControllerVariables" :> { Hold[$CellContext`n$$, $CellContext`n$5115$$, 0], Hold[$CellContext`sr$$, $CellContext`sr$5116$$, 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$$]; $CellContext`y = Which[$CellContext`n$$ == 10, 5, $CellContext`n$$ == 100, 15, $CellContext`n$$ == 1000, 50, $CellContext`n$$ == 10000, 220]; $CellContext`list = Accumulate[ RandomChoice[{-1, 1}, {$CellContext`n$$}]]; ListLinePlot[$CellContext`list, AxesOrigin -> {1, 0}, Axes -> {True, False}, Filling -> Axis, PlotRange -> {{ 0, $CellContext`n$$}, {-$CellContext`y, $CellContext`y}}, Ticks -> None, PlotLabel -> Style[ Column[{"percent of time in the lead", Row[{"heads = ", N[100 ((Count[ Part[$CellContext`list, Flatten[Position[$CellContext`list, 0] - 1]], Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x >= 0]] + Count[$CellContext`list, Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x > 0]])/ Length[$CellContext`list])]}], Row[{"tails = ", N[100 ((Count[ Part[$CellContext`list, Flatten[Position[$CellContext`list, 0] - 1]], Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x <= 0]] + Count[$CellContext`list, Condition[ Pattern[$CellContext`x, Blank[]], $CellContext`x < 0]])/ Length[$CellContext`list])]}]}], "Label"], ImageSize -> {450, 300}]), "Specifications" :> {{{$CellContext`n$$, 1000, "number of tosses"}, {10, 100, 1000, 10000}}, {{$CellContext`sr$$, 123, "random seed"}, 1, 12345, 1}}, "Options" :> {TrackedSymbols :> {$CellContext`n$$, $CellContext`sr$$}}, "DefaultOptions" :> {ControllerLinking -> True}], ImageSizeCache->{494., {204., 209.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, SynchronousInitialization->True, UnsavedVariables:>{Typeset`initDone$$}, UntrackedVariables:>{Typeset`size$$}], "Manipulate", Deployed->True, StripOnInput->False], Manipulate`InterpretManipulate[1]]], "Output", CellID->40982021] }, Open ]], Cell[CellGroupData[{ Cell["", "DetailsSection"], Cell[TextData[{ "W. Feller, \"Fluctuations in Coin Tossing and Random Walks\", ", StyleBox["An Introduction to Probability Theory and Its Applications", FontSlant->"Italic"], ", Vol. 1, New York: John Wiley & Sons, Inc., 1950 pp. 67-97." }], "DetailNotes", CellChangeTimes->{ 3.35696210375764*^9, {3.384525789402259*^9, 3.384525791339759*^9}, 3.384625701742121*^9}, CellID->275693065] }, Open ]], Cell[CellGroupData[{ Cell["", "ControlSuggestionsSection"], Cell[BoxData[ TooltipBox[ RowBox[{ CheckboxBox[True], Cell[" Resize Images"]}], "\"Click inside an image to reveal its orange resize frame.\\nDrag any of \ the orange resize handles to resize the image.\"", ActionDelay->0.35]], "ControlSuggestions", FontFamily->"Verdana", CellTags->"ResizeImages"], Cell[BoxData[ TooltipBox[ RowBox[{ CheckboxBox[False], Cell[" Rotate and Zoom in 3D"]}], RowBox[{ "\"Drag a 3D graphic to rotate it. Starting the drag near the center \ tumbles\\nthe graphic; starting near a corner turns it parallel to the plane \ of the screen.\\nHold down \"", FrameBox[ "Ctrl", Background -> GrayLevel[0.9], FrameMargins -> 2, FrameStyle -> GrayLevel[0.9]], "\" (or \"", FrameBox[ "Cmd", Background -> GrayLevel[0.9], FrameMargins -> 2, FrameStyle -> GrayLevel[0.9]], "\" on Mac) and drag up and down to zoom.\""}], ActionDelay->0.35]], "ControlSuggestions", FontFamily->"Verdana", CellTags->"RotateAndZoomIn3D"], Cell[BoxData[ TooltipBox[ RowBox[{ CheckboxBox[False], Cell[" Drag Locators"]}], RowBox[{"\"Drag any locator (\"", GraphicsBox[ LocatorBox[ Scaled[{0.5, 0.5}]], ImageSize -> 20], "\", etc.) to move it around.\""}], ActionDelay->0.35]], "ControlSuggestions", FontFamily->"Verdana", CellTags->"DragLocators"], Cell[BoxData[ TooltipBox[ RowBox[{ CheckboxBox[False], Cell[" Create and Delete Locators"]}], RowBox[{"\"Insert a new locator in the graphic by holding down the \"", FrameBox[ "Alt", Background -> GrayLevel[0.9], FrameMargins -> 2, FrameStyle -> GrayLevel[0.9]], "\" key\\nand clicking where you want it to be. Delete a locator by \ clicking it\\nwhile holding down the \"", FrameBox[ "Alt", Background -> GrayLevel[0.9], FrameMargins -> 2, FrameStyle -> GrayLevel[0.9]], "\" key.\""}], ActionDelay->0.35]], "ControlSuggestions", FontFamily->"Verdana", CellTags->"CreateAndDeleteLocators"], Cell[BoxData[ TooltipBox[ RowBox[{ CheckboxBox[True], Cell[" Slider Zoom"]}], RowBox[{"\"Hold down the \"", FrameBox[ "Alt", Background -> GrayLevel[0.9], FrameMargins -> 2, FrameStyle -> GrayLevel[0.9]], "\" key while moving a slider to make fine adjustments in the slider \ value.\\nHold \"", FrameBox[ "Ctrl", Background -> GrayLevel[0.9], FrameMargins -> 2, FrameStyle -> GrayLevel[0.9]], "\" and/or \"", FrameBox[ "Shift", Background -> GrayLevel[0.9], FrameMargins -> 2, FrameStyle -> GrayLevel[0.9]], "\" at the same time as \"", FrameBox[ "Alt", Background -> GrayLevel[0.9], FrameMargins -> 2, FrameStyle -> GrayLevel[0.9]], "\" to make ever finer adjustments.\""}], ActionDelay->0.35]], "ControlSuggestions", FontFamily->"Verdana", CellTags->"SliderZoom"], Cell[BoxData[ TooltipBox[ RowBox[{ CheckboxBox[False], Cell[" Gamepad Controls"]}], "\"Control this Demonstration with a gamepad or other\\nhuman interface \ device connected to your computer.\"", ActionDelay->0.35]], "ControlSuggestions", FontFamily->"Verdana", CellTags->"GamepadControls"], Cell[BoxData[ TooltipBox[ RowBox[{ CheckboxBox[False], Cell[" Automatic Animation"]}], RowBox[{"\"Animate a slider in this Demonstration by clicking the\"", AdjustmentBox[ Cell[ GraphicsData[ "CompressedBitmap", "eJzzTSzJSM1NLMlMTlRwL0osyMhMLlZwyy8CCjEzMjAwcIKwAgOI/R/IhBKc\n\ /4EAyGAG0f+nTZsGwgysIJIRKsWKLAXGIHFmEpUgLADxWUAkI24jZs+eTaEt\n\ IG+wQKRmzJgBlYf5lhEA30OqWA=="], "Graphics", ImageSize -> {9, 9}, ImageMargins -> 0], BoxBaselineShift -> 0.1839080459770115, BoxMargins -> {{0., 0.}, {-0.1839080459770115, 0.1839080459770115}}], "\"button\\nnext to the slider, and then clicking the play button that \ appears.\\nAnimate all controls by selecting \"", StyleBox["Autorun", FontWeight -> "Bold"], "\" from the\"", AdjustmentBox[ Cell[ GraphicsData[ "CompressedBitmap", "eJyNULENwyAQfEySIlMwTVJlCGRFsosokeNtqBmDBagoaZjAI1C8/8GUUUC6\n\ 57h7cQ8PvU7Pl17nUav7oj/TPH7V7b2QJAUAXBkKmCPRowxICy64bRvGGNF7\n\ X8CctGoDSN4xhIDGGDhzFXwUh3/ClBKrDQPmnGXtI6u0OOd+tZBVUqy1xSaH\n\ UqiK6pPe4XdEdAz6563tx/gejuORGMxJaz8mdpJn7hc="], "Graphics", ImageSize -> {10, 10}, ImageMargins -> 0], BoxBaselineShift -> 0.1839080459770115, BoxMargins -> {{0., 0.}, {-0.1839080459770115, 0.1839080459770115}}], "\"menu.\""}], ActionDelay->0.35]], "ControlSuggestions", FontFamily->"Verdana", CellTags->"AutomaticAnimation"], Cell[BoxData[ TooltipBox[ RowBox[{ CheckboxBox[False], Cell[" Bookmark Animation"]}], RowBox[{ "\"See a prepared animation of this Demonstration by selecting\\n\"", StyleBox["Animate Bookmarks", FontWeight -> "Bold"], "\" from the\"", AdjustmentBox[ Cell[ GraphicsData[ "CompressedBitmap", "eJyNULENwyAQfEySIlMwTVJlCGRFsosokeNtqBmDBagoaZjAI1C8/8GUUUC6\n\ 57h7cQ8PvU7Pl17nUav7oj/TPH7V7b2QJAUAXBkKmCPRowxICy64bRvGGNF7\n\ X8CctGoDSN4xhIDGGDhzFXwUh3/ClBKrDQPmnGXtI6u0OOd+tZBVUqy1xSaH\n\ UqiK6pPe4XdEdAz6563tx/gejuORGMxJaz8mdpJn7hc="], "Graphics", ImageSize -> {10, 10}, ImageMargins -> 0], BoxBaselineShift -> 0.1839080459770115, BoxMargins -> {{0., 0.}, {-0.1839080459770115, 0.1839080459770115}}], "\"menu.\""}], ActionDelay->0.35]], "ControlSuggestions", FontFamily->"Verdana", CellTags->"BookmarkAnimation"] }, Open ]], Cell[CellGroupData[{ Cell["", "SearchTermsSection"], Cell["ballot problem", "SearchTerms", CellChangeTimes->{ 3.35696210375764*^9, {3.383746584453125*^9, 3.383746593203125*^9}, { 3.383746646296875*^9, 3.383746660390625*^9}}, CellID->333924446], Cell["Bertrand ballot theorem", "SearchTerms", CellChangeTimes->{ 3.35696210375764*^9, {3.383746584453125*^9, 3.383746593203125*^9}, { 3.383746646296875*^9, 3.38374667915625*^9}}, CellID->246251111], Cell["heads minus tails distribution", "SearchTerms", CellChangeTimes->{ 3.35696210375764*^9, {3.38374668025*^9, 3.38374669709375*^9}}, CellID->67258962], Cell["long runs", "SearchTerms", CellChangeTimes->{ 3.35696210375764*^9, {3.383746697640625*^9, 3.38374669984375*^9}}, CellID->349250385] }, Open ]], Cell[CellGroupData[{ Cell["", "RelatedLinksSection"], Cell[TextData[ButtonBox["Heads-Minus-Tails Distribution", BaseStyle->"Hyperlink", ButtonData->{ URL["http://mathworld.wolfram.com/Heads-Minus-TailsDistribution.html"], None}]], "RelatedLinks", CellChangeTimes->{ 3.35696210375764*^9, {3.383746724*^9, 3.383746766734375*^9}, { 3.3837473916580424`*^9, 3.383747405987726*^9}}, CellID->32922046], Cell[TextData[ButtonBox["Ballot Problem", BaseStyle->"Hyperlink", ButtonData->{ URL["http://mathworld.wolfram.com/BallotProblem.html"], None}]], "RelatedLinks", CellChangeTimes->{ 3.35696210375764*^9, {3.3837474624938736`*^9, 3.3837474782612133`*^9}}, CellID->202140410], Cell[TextData[ButtonBox["Random Walk--1-Dimensional", BaseStyle->"Hyperlink", ButtonData->{ URL["http://mathworld.wolfram.com/RandomWalk1-Dimensional.html"], None}]], "RelatedLinks", CellChangeTimes->{ 3.35696210375764*^9, {3.383747537486407*^9, 3.383747537486407*^9}}, CellID->48745765] }, Open ]], Cell[CellGroupData[{ Cell["", "AuthorSection"], Cell[TextData[{ "Contributed by: ", ButtonBox["Fiona Maclachlan", BaseStyle->"Hyperlink", ButtonData->{ URL["http://demonstrations.wolfram.com/author.html?author=Fiona+\ Maclachlan"], None}, ButtonNote-> "http://demonstrations.wolfram.com/author.html?author=Fiona+Maclachlan"] }], "Author", CellChangeTimes->{ 3.35696210375764*^9, {3.3837475508316083`*^9, 3.383747566536442*^9}}, CellID->14090163] }, Open ]] }, Open ]] }, WindowSize->{700, Automatic}, WindowMargins->{{233, Automatic}, {Automatic, 18}}, FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (June 19, 2007)", StyleDefinitions->FrontEnd`FileName[{"Wolfram"}, "Demonstration.nb", CharacterEncoding -> "WindowsANSI"] ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{ "ResizeImages"->{ Cell[25785, 603, 310, 8, 70, "ControlSuggestions", CellTags->"ResizeImages"]}, "RotateAndZoomIn3D"->{ Cell[26098, 613, 677, 16, 70, "ControlSuggestions", CellTags->"RotateAndZoomIn3D"]}, "DragLocators"->{ Cell[26778, 631, 339, 11, 70, "ControlSuggestions", CellTags->"DragLocators"]}, "CreateAndDeleteLocators"->{ Cell[27120, 644, 636, 15, 70, "ControlSuggestions", CellTags->"CreateAndDeleteLocators"]}, "SliderZoom"->{ Cell[27759, 661, 842, 21, 70, "ControlSuggestions", CellTags->"SliderZoom"]}, "GamepadControls"->{ Cell[28604, 684, 303, 8, 70, "ControlSuggestions", CellTags->"GamepadControls"]}, "AutomaticAnimation"->{ Cell[28910, 694, 1411, 31, 70, "ControlSuggestions", CellTags->"AutomaticAnimation"]}, "BookmarkAnimation"->{ Cell[30324, 727, 881, 21, 70, "ControlSuggestions", CellTags->"BookmarkAnimation"]} } *) (*CellTagsIndex CellTagsIndex->{ {"ResizeImages", 33888, 842}, {"RotateAndZoomIn3D", 33996, 845}, {"DragLocators", 34105, 848}, {"CreateAndDeleteLocators", 34220, 851}, {"SliderZoom", 34333, 854}, {"GamepadControls", 34438, 857}, {"AutomaticAnimation", 34550, 860}, {"BookmarkAnimation", 34666, 863} } *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[590, 23, 131, 2, 70, "DemoTitle"], Cell[724, 27, 33, 0, 70, "InitializationSection"], Cell[CellGroupData[{ Cell[782, 31, 29, 0, 70, "ManipulateSection"], Cell[CellGroupData[{ Cell[836, 35, 5141, 123, 70, "Input"], Cell[5980, 160, 3635, 76, 70, "Output", CellID->22635471] }, {2}]] }, Open ]], Cell[CellGroupData[{ Cell[9661, 242, 36, 0, 70, "ManipulateCaptionSection"], Cell[9700, 244, 885, 14, 70, "ManipulateCaption"] }, Open ]], Cell[CellGroupData[{ Cell[10622, 263, 28, 0, 70, "ThumbnailSection"], Cell[10653, 265, 3636, 76, 70, "Output", CellID->743974050] }, Open ]], Cell[CellGroupData[{ Cell[14326, 346, 28, 0, 70, "SnapshotsSection"], Cell[14357, 348, 3623, 76, 70, "Output", CellID->33166934], Cell[17983, 426, 3628, 76, 70, "Output", CellID->489102385], Cell[21614, 504, 3631, 76, 70, "Output", CellID->40982021] }, Open ]], Cell[CellGroupData[{ Cell[25282, 585, 26, 0, 70, "DetailsSection"], Cell[25311, 587, 397, 9, 70, "DetailNotes", CellID->275693065] }, Open ]], Cell[CellGroupData[{ Cell[25745, 601, 37, 0, 70, "ControlSuggestionsSection"], Cell[25785, 603, 310, 8, 70, "ControlSuggestions", CellTags->"ResizeImages"], Cell[26098, 613, 677, 16, 70, "ControlSuggestions", CellTags->"RotateAndZoomIn3D"], Cell[26778, 631, 339, 11, 70, "ControlSuggestions", CellTags->"DragLocators"], Cell[27120, 644, 636, 15, 70, "ControlSuggestions", CellTags->"CreateAndDeleteLocators"], Cell[27759, 661, 842, 21, 70, "ControlSuggestions", CellTags->"SliderZoom"], Cell[28604, 684, 303, 8, 70, "ControlSuggestions", CellTags->"GamepadControls"], Cell[28910, 694, 1411, 31, 70, "ControlSuggestions", CellTags->"AutomaticAnimation"], Cell[30324, 727, 881, 21, 70, "ControlSuggestions", CellTags->"BookmarkAnimation"] }, Open ]], Cell[CellGroupData[{ Cell[31242, 753, 30, 0, 70, "SearchTermsSection"], Cell[31275, 755, 197, 4, 70, "SearchTerms", CellID->333924446], Cell[31475, 761, 205, 4, 70, "SearchTerms", CellID->246251111], Cell[31683, 767, 157, 3, 70, "SearchTerms", CellID->67258962], Cell[31843, 772, 141, 3, 70, "SearchTerms", CellID->349250385] }, Open ]], Cell[CellGroupData[{ Cell[32021, 780, 31, 0, 70, "RelatedLinksSection"], Cell[32055, 782, 356, 8, 70, "RelatedLinks", CellID->32922046], Cell[32414, 792, 283, 7, 70, "RelatedLinks", CellID->202140410], Cell[32700, 801, 300, 7, 70, "RelatedLinks", CellID->48745765] }, Open ]], Cell[CellGroupData[{ Cell[33037, 813, 25, 0, 70, "AuthorSection"], Cell[33065, 815, 416, 12, 70, "Author", CellID->14090163] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)