It's the best time of the year for friends and family and the worst time of year for my gut. Between the office pot-lucks and ad-hoc bake offs there's bound to be a bad egg or two which results in the ever dreaded gargle gut. These holiday foods are particularly risky:
- Deviled Eggs
- Cheese sauce
- Boiled Hot Dogs
- Anything with the word "Salad" that's not actually a leaf salad
Let's say your office holds a New Years potluck party. You don't want to be rude so you show up and randomly select four items from the spread. What's the probability you picked one of the high risk items above?
We first need to identify all possible items to chose from. In addition to the items above we can also pick:
- Mashed potatoes
- Corn Casserole
- Broccoli Salad
- Cheese Salad
- Little Smokies
- Corn Bread
- Chocolate Chip Cookie
- Fruit Salad
- Beef Jerky
- Ham Sandwich
This gives a total of 17 items served for a total of 57,120 possible combinations to pick from. We won't double up on any item so after each choice our available options shrinks by one (17 x 16 x 15 x 14 = 57,120).
The formula for a probability of an outcome is:
Probability = Risky Combinations / Total Possible Combinations
At this point we know the denominator is 57,120 so we modify the equation:
Probability = Risky Combinations / 57,120
We'll use a sql solution to find our numerator.
T-SQL Hammer Time
First thing is we need to convert our list into a set so we can apply multiplication and logic to our items. For starters we'll create a set using a temp table:
DECLARE @PotluckFood TABLE (Item VARCHAR(25)) INSERT INTO @PotluckFood( Item ) Select 'Mashed potatoes' as Item Union all Select 'Muffin' as Item Union all Select 'Pie' as Item Union all Select 'Corn Casserole' as Item Union all Select 'Broccoli Salad' as Item Union all Select 'Cheese Salad' as Item Union all Select 'little smokies' as Item Union all Select 'Corn Bread' as Item Union all Select 'Chocolate Chip COOKIE' as Item Union all Select 'Fruit Salad' as Item Union all Select 'Beef Jerky' as Item Union all Select 'Ham Sandwich' as Item Union all Select 'Cake' as Item Union all Select 'Salami' as Item Union all Select 'Deviled Eggs' as Item Union all Select 'Cheese sauce' as Item Union all Select 'Boiled Hot Dogs' as Item
Aside - Notice the repetition in the code? Every line uses the words 'SELECT' and 'as Item Union all'. We can write this separately for each line or save keystrokes using the ALT-click trick. Just press and hold 'ALT' then click and drag down the editor. The keystrokes will be replicated across the lines. This trick works in NotePad ++ as well.
We can find the total possible combinations by performing a self 'CROSS JOIN' three times. The WHERE clause enforces the logic that we will not select the same item twice.
SELECT * FROM @PotluckFood AS Item1 CROSS JOIN @PotluckFood AS Item2 CROSS JOIN @PotluckFood AS Item3 CROSS JOIN @PotluckFood AS Item4 WHERE ( Item1.Item <> Item2.Item AND Item1.ITem <> Item3.Item AND Item1.ITem <> Item4.Item AND Item2.ITem <> Item1.Item AND Item2.ITem <> Item3.Item AND Item2.ITem <> Item4.Item AND Item3.ITem <> Item1.Item AND Item3.ITem <> Item2.Item AND Item3.ITem <> Item4.Item AND Item4.ITem <> Item1.Item AND Item4.ITem <> Item2.Item AND Item4.ITem <> Item3.Item )
Now we can visually spot the check the list of possible combinations.
We can find high risk combinations by appending this logic to our WHERE clause:
AND ( Item1.Item IN ('Salami','Deviled Eggs','Cheese Sauce','Boiled Hot Dogs' ) or Item1.Item LIke '%Salad' OR Item2.Item IN ('Salami','Deviled Eggs','Cheese Sauce','Boiled Hot Dogs' ) or Item2.Item LIke '%Salad' OR Item3.Item IN ('Salami','Deviled Eggs','Cheese Sauce','Boiled Hot Dogs' ) or Item3.Item LIke '%Salad' OR Item4.Item IN ('Salami','Deviled Eggs','Cheese Sauce','Boiled Hot Dogs' ) or Item4.Item LIke '%Salad' )
We now have our numerator:
Our equation can be solved:
52,080 / 57,120 = .912
At a 91.2% percent chance of selecting one of the risky foods we'd be wise to invest in a few rolls of tums.