16 Bags
I know the question was phrased as a sort of math problem, but most LEGO fans solve it as a sort of LEGO problem. The bags are opaque, so you cannot see what's in the bags, but almost everywhere they are sold you can feel the bags, and you can determine what figure is in the bag. With the exception of the recent Soccer Team figures, collectible minifigures are always unique in terms of what parts are in the bag. Just shake and squeeze the bag until the distinctive piece is found.
The problem with the math way: One can compute the probability of, say, picking two matching socks out of a drawer of miscellaneous socks, or of picking a whole collection of figures out of a box of figures. But there are a few complications:
- Someone else has been there before you and squeezed the bags to find all the space marines.
- Someone else has been there before you and grabbed a few at random, but then squeezed a few more bags to find the Princess.
- The store takes what's left from the first box and jams it into the second box when the box runs low; or they don't even display them in the original box, making it impossible to know how many boxes are in play and how many figures have been picked.
- There are usually 16 figures in a collection and 60 figures in a box; this means the figures cannot be evenly distributed. Some series have had as few as two of one figure in the box. Given that, it's entirely possible (though unlikely) to pick 58 figures and miss both of that elusive Unicorn Girl.
If squeezing the bags isn't an option, the only way to be sure is to buy a new, unopened box.