Cell[CellGroupData[{Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{ RowBox[{"SeedRandom", "[", "sr", "]"}], ";", " ", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"jj", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"RandomInteger", "[", RowBox[{"{", RowBox[{"1", ",", "coupons"}], "}"}], "]"}], ",", RowBox[{"{", RowBox[{"20", " ", "coupons"}], "}"}]}], "]"}]}], "}"}], ",", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"store", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Length", "[", RowBox[{"Union", "[", RowBox[{"Take", "[", RowBox[{"jj", ",", "k"}], "]"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"k", ",", "1", ",", RowBox[{"Length", "[", "jj", "]"}]}], "}"}]}], "]"}]}], "}"}], ",", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"list", "=", RowBox[{"Flatten", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{"First", "[", RowBox[{"Position", "[", RowBox[{"store", ",", "n"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"n", ",", "1", ",", "coupons"}], "}"}]}], "]"}], "]"}]}], "}"}], ",", RowBox[{"ListPlot", "[", RowBox[{"list", ",", RowBox[{"PlotRange", "->", "All"}], ",", RowBox[{"Frame", "->", "True"}], ",", RowBox[{"Axes", "->", "False"}], ",", RowBox[{"FrameLabel", "->", RowBox[{"{", RowBox[{ RowBox[{"Style", "[", RowBox[{ "\"\\"", ",", "\"\\""}], "]"}], ",", RowBox[{"Style", "[", RowBox[{ "\"\\"", ",", "\"\\""}], "]"}]}], "}"}]}], ",", RowBox[{"PlotLabel", "->", RowBox[{"Style", "[", RowBox[{ RowBox[{ RowBox[{"ToString", "[", RowBox[{"Last", "[", "list", "]"}], "]"}], "<>", "\"\< coupons had to be bought for the complete set \ of \>\"", "<>", RowBox[{"ToString", "[", "coupons", "]"}], "<>", "\"\<.\\nThe expected number was \>\"", "<>", RowBox[{"ToString", "[", RowBox[{"Round", "[", RowBox[{"coupons", " ", RowBox[{"HarmonicNumber", "[", "coupons", "]"}]}], "]"}], "]"}], "<>", "\"\<.\>\""}], ",", "\"\\""}], "]"}]}], ",", RowBox[{"ImagePadding", "->", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"35", ",", "25"}], "}"}], ",", RowBox[{"{", RowBox[{"35", ",", "35"}], "}"}]}], "}"}]}], ",", RowBox[{"ImageSize", "->", RowBox[{"{", RowBox[{"475", ",", "375"}], "}"}]}]}], "]"}]}], "]"}]}], "]"}]}], "]"}]}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ "coupons", ",", "50", ",", "\"\\""}], "}"}], ",", "6", ",", "100", ",", "1", ",", RowBox[{"Appearance", "->", "\"\\""}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"sr", ",", "1", ",", "\"\\""}], "}"}], ",", "1", ",", "400", ",", "1", ",", RowBox[{"Appearance", "->", "\"\\""}]}], "}"}]}], "]"}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{ 3.35696210375764*^9, 3.3833288962021947`*^9, { 3.3833289519365697`*^9, 3.3833290269990697`*^9}, { 3.3876337133172293`*^9, 3.38763372598709*^9}, 3.760741526351036*^9}, CellID->162139775], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`coupons$$ = 50, $CellContext`sr$$ = 1, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{{ Hold[$CellContext`coupons$$], 50, "number of distinct coupons"}, 6, 100, 1}, {{ Hold[$CellContext`sr$$], 1, "seed random"}, 1, 400, 1}}, Typeset`size$$ = {475., {185., 190.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = True, $CellContext`coupons$46447$$ = 0, $CellContext`sr$46448$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`coupons$$ = 50, $CellContext`sr$$ = 1}, "ControllerVariables" :> { Hold[$CellContext`coupons$$, $CellContext`coupons$46447$$, 0], Hold[$CellContext`sr$$, $CellContext`sr$46448$$, 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$$]; With[{$CellContext`jj$ = Table[ RandomInteger[{1, $CellContext`coupons$$}], { 20 $CellContext`coupons$$}]}, With[{$CellContext`store$ = Table[ Length[ Union[ Take[$CellContext`jj$, $CellContext`k]]], \ {$CellContext`k, 1, Length[$CellContext`jj$]}]}, With[{$CellContext`list$ = Flatten[ Table[ First[ Position[$CellContext`store$, $CellContext`n]], \ {$CellContext`n, 1, $CellContext`coupons$$}]]}, ListPlot[$CellContext`list$, PlotRange -> All, Frame -> True, Axes -> False, FrameLabel -> { Style["distinct coupons bought", "Label"], Style["total coupons bought", "Label"]}, PlotLabel -> Style[ StringJoin[ ToString[ Last[$CellContext`list$]], " coupons had to be bought for the complete set of ", ToString[$CellContext`coupons$$], ".\nThe expected number was ", ToString[ Round[$CellContext`coupons$$ HarmonicNumber[$CellContext`coupons$$]]], "."], "Label"], ImagePadding -> {{35, 25}, {35, 35}}, ImageSize -> {475, 375}]]]]), "Specifications" :> {{{$CellContext`coupons$$, 50, "number of distinct coupons"}, 6, 100, 1, Appearance -> "Labeled"}, {{$CellContext`sr$$, 1, "seed random"}, 1, 400, 1, Appearance -> "Labeled"}}, "Options" :> {}, "DefaultOptions" :> {ControllerLinking -> True}], ImageSizeCache->{520., {244., 250.}}, 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.760741526351303*^9}, CellID->423568870] }, {2}]]