Skip to main content
2 of 4
added 362 characters in body
kglr
  • 400.5k
  • 18
  • 488
  • 929

We need a custom control because TogglerBar does not quite do the job as it shows the value that is being clicked and it allows opened briefcases to be closed again with the next click. With the function togglerGrid below (1) we cannot see the contents of the briefcase until it is opened, and (2) once a briefcase is opened it remains open.

ClearAll[togglerGrid]
togglerGrid[Dynamic[y_], vals_, dims_, size_: {20, 20}, col_: LightGray] := 
 Deploy @ Grid[ArrayReshape[
    Table[With[{i = i}, 
      Item[Setter[Dynamic[MemberQ[y, i], If[! MemberQ[y, i], AppendTo[y, i]] &], 
        {True}, i, Appearance -> None, Alignment -> Center, ImageSize -> size], 
       ItemSize -> {All, 1}, Frame -> White, FrameStyle -> Thick,
       BaseStyle -> Dynamic[If[MemberQ[y, i], Black, col]], 
       Background -> Dynamic[If[MemberQ[y, i], Lighter@Lighter@col, col]]]], {i, 
      vals}], dims, ""], Spacings -> {.1, .1}, 
   Dividers -> All, FrameStyle -> White, Alignment -> {Center, Center}, 
   ItemStyle -> FontSize -> 16]

A few non-functional elements for embellishments:

logo = Row[{Text[Framed[Style[" DEAL ", FontFamily -> "Stencil", FontSize -> 73, 
       FontColor -> Black, FontWeight -> "Plain"], Background -> Red]],
    Framed[Style[" NODEAL ", FontFamily -> "Stencil", FontSize -> 73, 
      FontColor -> Red, FontWeight -> "Plain"], Background -> Black]}];

briefcase = Graphics[{Rectangle[{0, 0}, {3, 2}, "RoundingRadius" -> .15], 
    Annulus[{3/2, 3/2}, {7/10, 8/10}], 
    White, Disk[{1, 2/3}, {.1, .15}], Disk[{2, 2/3}, {.1, .15}], 
    Thick, Line[{{0, 2/3}, {3, 2/3}}]}];


values = {0.01, 1, 5, 10, 25, 50, 75, 100, 200, 300, 400, 500, 750, 
   1000, 5000, 10000, 25000, 50000, 75000, 100000, 200000, 300000, 
   400000, 500000, 750000, 1000000};

... and a Manipulate:

We shuffle values as initialization and assume the first briefcase is the one taken by the player. We update the data sets fed into BoxWhiskerChart as the remaining briefcases are opened. The top-right briefcase shows the expected value of currently closed briefcases. We use log-scaling in BoxWhiskerChart because with linear scaling the charts look too squeezed at the bottom.

Style[#, DefaultOptions -> {Panel -> {Background -> ColorData["HTML", "Gold"]}}] & @
 Manipulate[Labeled[
    BoxWhiskerChart[PadRight[Complement[rs, Take[a, #]] & /@ Range[0, Length@a], 
      Length@values, {{}}], ScalingFunctions -> "Log", 
    Background -> White, ImageSize -> {600, 400}, Joined -> True, 
    ChartLabels -> Placed[Range[25], Axis], ChartStyle -> "Rainbow", 
    GridLines -> {{5, 10, 15, 20, 25}, None}], logo, Top], 
  Column[{Dynamic @ Panel @ Magnify[Show[briefcase, 
        Epilog -> Text[If[Length@Complement[rs, a] == 1, 
           Style[First @ rs , Red, FontSize -> Scaled[.15]], 
           Style["?" , Red, Bold, FontSize -> Scaled[.4]]], {3/2, 5/4}]], 1/3], 
    Control @ {{a, {}, ""}, rs, togglerGrid[#, Rest@rs, {13, 2}, {70, 30}] &}, 
    Control@{{rs, RandomSample[values]}, None}}, Alignment -> Center],
   Column[{Dynamic @ Panel @ Magnify[
       Show[briefcase, Epilog -> Text[Style[
           Column[{Style["Expected Value", White, FontSize -> Scaled[.1]], 
             Row[{"$ ", N @ Mean[Complement[rs, a]]}]}, 
            Alignment -> Center], Red, FontSize -> Scaled[.15]], {3/2, 5/4}]], 1/3], 
    Grid[Partition[Map[Item[Pane[Dynamic @ Style[#, 16, If[MemberQ[a, #], White, Black]], 
          ImageSize -> {70, 30}, Alignment -> {Right, Center}], 
         Background -> Dynamic @ If[MemberQ[a, #], ColorData["HTML", "Goldenrod"], 
            White]] &, Reverse @ values], 2],
     Spacings -> {.1, .1}, Dividers -> All, FrameStyle -> White]}, Alignment -> Center], 
  ControlPlacement -> {Left, Right}, 
  Method -> {"ContentAreaBackground" -> ColorData["HTML", "Gold"]}, 
  AppearanceElements -> {}]

Screenshots:

enter image description here

enter image description here

enter image description here

enter image description here

kglr
  • 400.5k
  • 18
  • 488
  • 929