Showing posts with label Probability and Statistics. Show all posts
Showing posts with label Probability and Statistics. Show all posts

Saturday, February 22, 2014

Gambler's Ruin Problem Part 4: Odds in Video Poker

Click here to see part 1 of this four week series.
Click here to see part 2 of this four week series.
Click here to see part 3 of this four week series.


Suppose that you find yourself in a city with a casino and you have $60 in your pocket. There is a concert in town that you really want to see, but the tickets cost $100. You decide that you will place $1 bets until you either reach $100 or go broke. Which casino game should you play? How likely are you to reach your goal of $100?

This week is the final week in my series on the Gambler's Ruin Problem, which I have explained again in the paragraph above. We have analyzed roulette, craps, and blackjack, finding out various odds, expected values, and success probabilities. Here is what we have so far:

GameAvg Gain Per $1 BetP of Reaching $100
Favorable Game (51-49 odds)92.6%
Fair Game (50-50 odds)60%
Blackjack-0.5¢47.8%
Craps-1.4¢28%
Roulette-5.3¢1.3%

Let's see how video poker fairs. I chose not to do Texas Hold'em or another popular version of real poker because there is so much strategy involved, and determining a universal statistic is near to impossible. If you are also considering reading players, pot odds, and the occasional bluff, it becomes extremely complicated. However, video poker is another game that is you against the house and can be played with a more concrete strategy like blackjack. Let's go over the rules.


As you can see in the picture, video poker is pretty much a slot machine, except it gives much better odds. The game of poker played on it is five card draw. The player is given five cards to start. They then are given the opportunity to either keep them all, get rid of one, get rid of two, get rid of three, get rid of four, or get rid of all of them. The cards they got rid of are then replaced, and the hand they have left is identified and the proper money exchange is made. If you are unfamiliar with the poker hands, click here. This is the list of odds the casino gives for each hand:

Royal Flush - 250:1
Straight Flush - 50:1
Four of a Kind - 25:1
Full House - 9:1
Flush - 6:1
Straight - 4:1
Three of a Kind - 3:1
Two Pair - 2:1
Pair of Jacks or Better - 1:1


As you can see, the rarer the hand, the bigger the payoff is. This creates the difficulty in choosing which cards to hold and which to discard in any given turn.

I will start by just going through the basic strategy. Then, we will look at some of the exceptions and why they are encouraged.

1. With two pair or higher, keep the cards needed for the hand and discard the rest (for instance, draw one card in a two pair, don't draw any in a flush)
2. With one pair, keep the pair and discard the rest
3. With no high cards, discard all five
4. With one high card, keep it and discard the rest
5. With two high cards, keep them and discard the rest
6. With three or four high cards, keep two. If there are two of the same suit, keep them. Otherwise, take the two with the lowest value.

Pretty simple when it comes to poker strategy. That one won't take up an entire book. Now let's look at some exceptions. The first one is the following:

If four cards are in a straight flush, discard the fifth one (but don't break a straight or flush unless it can become a royal flush)

For instance, take the following example:

7C  8C  9C  JC  JD

In this hand, the basic strategy would say to discard the seven eight and nine, but this exception tells us to discard the jack of diamonds. Let's see why. There are 52 cards in a deck, and five have been used in this hand. So, the remaining possibilities to take the place of the jack of diamonds should total 47.

Here are the possible hands and their probabilities:

P(Straight Flush) = 1/47
P(Flush) = 8/47
P(Straight) = 3/47
P(2 Jacks) = 2/47
P(Nothing) = 33/47

EV(Discard JD) = (1/47)(50) + (8/47)(6) + (3/47)(4) + (2/47)(1) + (33/47)(-1) = 79/47 ≈ $1.68

And here are the possible hands and their probabilities for keeping the jacks:

P(4 of a Kind) = (3 ways of choosing)(2/47 third jack options)(1/46 fourth jack options) = 3/1081
P(Full House) = (3 ways of choosing placement of third jack)(2/47 third jack options)(46/46 • 3/45 pair options) + (12 value choices of three of a kind)(4/47 first cards)(3/46 second cards)(2/45 third cards) = 62/5405
P(3 Jacks) = (3 ways of choosing placement of third jack)(2/47 third jack options) = 6/47
P(2 Pair) = (3 ways of choosing)(47/47 • 3/46 pair options) = 9/46
P(2 Jacks) = 1 - P(4 of a Kind) - P(Full House) - P(3 Jacks) - P(2 Pair) = 7161/10810

EV(Keep Jacks) = (3/1081)(25) + (62/5405)(9) + (6/47)(3) + (9/46)(2) + (7161/10810)(1) = 17397/10810 ≈ $1.61

As you can see, keeping the jacks has less of a payoff than this exception. It isn't a huge difference, but still one to take note of.

Here are some other exceptions:

If you have four cards in a flush, go for the flush.
If you have three cards in a royal flush, go for the royal flush.
If you have an open-ended straight, go for the straight.
If you have three straight flush cards, go for the straight flush.
If you have J 10 suited, Q 10 suited or K 10 suited, keep the 10 in addition to the high card.

All of those exceptions could be proven with the probability techniques. Using this strategy, you will have very similar odds to blackjack with about a 0.5¢ loss per turn. Most players will lose 4¢ per turn, so this puts us way ahead of the game.

GameAvg Gain Per $1 BetP of Reaching $100
Favorable Game (51-49 odds)92.6%
Fair Game (50-50 odds)60%
Blackjack-0.5¢47.8%
Video Poker-0.5¢47.8%
Craps-1.4¢28%
Roulette-5.3¢1.3%
Average Vegas Slot Machine-6.6¢0.5%

I added an average for Vegas slot machines onto the bottom of our table just to give a taste as to how bad their odds are. Of course, each slot machine varies and I'm not sure how accurate the information I found was for them. But the odds for the games we discussed are all completely based on mathematics and are a lot of fun to play around with. If you play other games in the casino, I'm sure you can determine all of the same information for the Gambler's Ruin Problem and looking for optimal strategy.

So what's the answer to the Gambler's Ruin Problem? I don't know. We took a close look at many different games, but we can never have enough information to have a solid answer. There are dozens of different games and bets out there, many of whom can't be completely analyzed with probability and game theory. But this problem is a gateway to having fun with numbers and probability to make yourself a better player at the casino and learn a bit about mathematics. I hope some of the things we've learned in the last month become useful to you next time you have sixty bucks in a city with a casino.

Saturday, February 15, 2014

Gambler's Ruin Problem Part 3: Odds in Blackjack

Click here to see part 1 of this four week series.
Click here to see part 2 of this four week series.


We spent the last two weeks talking about the Gambler's Ruin Problem and how it is a gateway to analyze different games like craps and roulette. Here is a refresher of what we have discovered so far, as well as what the Gambler's Ruin Problem is:

Suppose that you find yourself in a city with a casino and you have $60 in your pocket. There is a concert in town that you really want to see, but the tickets cost $100. You decide that you will place $1 bets until you either reach $100 or go broke. Which casino game should you play? How likely are you to reach your goal of $100?

And here were the probabilities we found for all bets in roulette, the pass line bet in craps, and the other two control statistics.

GameAvg Gain Per $1 BetP of Reaching $100
Favorable Game (51-49 odds)92.6%
Fair Game (50-50 odds)60%
Craps-1.4¢28%
Roulette-5.3¢1.3%

We found that roulette is a game of minimal strategy; each bet had the same expected value. Craps is a more difficult game because of the many different bet options each with different perks and odds, but players still don't have to worry about utilizing strategies on the fly. Blackjack starts to get into some more complicated strategy building.


Though there are other players at the table, like craps and roulette, blackjack is a game of you against the house (which is represented by the dealer). You will receive two face up cards and the dealer will receive one face up and one face down card. The sum of the numbers on the card is what your total is (J = 10, Q = 10, K = 10, A = 1 or 11). For instance, K 2 would be 12, 9 7 would be 16, A 5 would be 6 or 16. Hands with an ace counting for eleven are called soft hands because they are easier to work with; they can be lowered by ten at any time if need be.

Once you get your two hands, the dealer will ask if you want to "hit" or "stand." Hitting is when you take another card and add it to your total. Standing is when you do not take any more cards and your hand becomes final. If you hit and your total goes over 21, you "bust" and lose your bet.

Once everyone at the table stands or busts, the dealer then turns over his facedown card. He then must hit until his total is 17 or above. Once he gets to there, he must stand. You then lose your bet if his/her total beats yours and you get even money (1:1) if you beat his/her total.

When you get 21 with just two cards (A K, A J, etc), your hand is called blackjack. As you can see on the table above, blackjack pays 3:2 instead of just 1:1. This is one of the perks that you have as a player; the dealer cannot request that you pay him extra because he got blackjack.

As a player, you also have a few additional betting options that I will explain below.

Doubling Down is when you double your bet on the table and agree to only take one more card. With certain types of starting hands, you can increase your payoff in this way.

Splitting is only allowed when you have two cards of the same number. You can "split" the cards, put a second equal bet on the other card, and play both hands simultaneously against the dealer. Most casinos let you re-split cards, but rarely do they let you double down after splitting.

Taking Insurance is only allowed when the dealer's face up card is an ace. You can bet up to half of your original bet that the dealer's facedown card is a 10, J, Q, or K. This bet pays 2:1, as depicted on the table above.

Blackjack doesn't have to deal with as many weird ratios and random bets as craps does, but developing strategy becomes more difficult because of this. Aside from taking insurance, it is all just inflicting different probabilities into a lone 1:1 bet. But how can we optimize our odds on this 1:1 bet?

When you think about it, it seems like you have a pretty big advantage over the dealer. You can stand before 17, hit after 17, split, double down, take insurance, and get paid 3:2 on blackjack. How do the casinos make money? Well, there is one thing that the dealer has an advantage on, which doesn't even cross our minds. Every time you bust, you lose. Even if the dealer busts. This one advantage is what makes blackjack worth it for the casinos.

This doesn't mean that we can't try our best though. A beginner might just make random bets based on intuition, but more experienced players are able to get their odds much closer to 1:1. Let's start with looking at when to hit or stand. First, hard hands:

Dealer's Up Card Hit Until You Reach
7, 8, 9, 10, A 17
4, 5, 6 12
2, 3 13

So let's say your starting hand is 7 2 and the dealer is showing a 3.

7 2
? 3

Your total is nine, and you hit until you reach 13. So you hit.

7 2 2
? 3

Now your total is eleven, so you must hit again.

7 2 2 K
? 3

Now your total is 21, and you obviously would stand here.

7 2 2 K
5 3 J

You win! Great job. That guideline is probably the most basic part of the strategy, and will come into play in almost every round. If you memorize any of the strategies I discuss here, that is the one to remember.

That was for hard hands (without an ace acting as an eleven). What about soft hands?

Dealer's Up CardHit Until You Reach
9, 10, ASoft 19
8 or belowSoft 18

Let's try it.

A 5
? 9

Our strategy says we should hit.

A 5 7
? 9

Now we have a hard hand of thirteen, so we must switch back to the hard hand strategy and hit until we reach seventeen.

A 5 7 4
? 9

This is one of the most debated parts of blackjack. We have a hand totaling sixteen and we need to hit or stand. Many players are conservative and choose to stand here. However, we know that probability tells us to hit. You could map out all of the possible outcomes of this hand for yourself and the dealer and compare them, and you would find that hitting actually does end up giving you more success.

A 5 7 4 Q
? 9

And you busted.

A 5 7 4 Q
K 9

But you would have lost anyways, so hitting was worth a try on that one. Now let's look at double down and splitting strategies.

Your First Two CardsDouble if Dealer Has
Total 1110 or below
Total 109 or below
Total 94, 5, 6
A2 through A74, 5, 6

When do you splitIf Dealer Has
A, 8any card
4, 5, 10never
2, 3, 6, 72, 3, 4, 5, 6
92, 3, 4, 5, 6, 8, 9

Those are for doubling down and splitting. What about taking insurance? This is the easiest rule of them all.

Don't take insurance

Ever. Let's look at why. The dealer's face down card could be any of the following:

A  2  3  4  5  6  7  8  9  10  J  Q  K

There are nine cards that don't win you the bet and four cards that do. So, the fair odds for the casino to offer would be 9:4. But, they only offer 2:1 or 8:4, meaning that insurance is not worth it (unless you are a card counter).

If you figure out the expected value of your $1 bet incorporating all of these strategies, you end up getting an average loss of 0.5¢. This is much better than craps and roulette! These are the best odds we have seen so far!

GameAvg Gain Per $1 BetP of Reaching $100
Favorable Game (51-49 odds)92.6%
Fair Game (50-50 odds)60%
Blackjack-0.5¢47.8%
Craps-1.4¢28%
Roulette-5.3¢1.3%

These odds are not bad. In fact, we are not far from having a 50-50 shot of turning our $60 into $100!

This strategy is great. But what I always wonder is why it works. Why do we hit on sixteen if the dealer has a seven showing? Let's figure it out.

First, we determine the dealer's odds of busting with a seven. To do this, we start with the odds of busting with sixteen (the dealer won't bust if they get to seventeen because they are required to stand). This is a sum of their odds of getting a 6, 7, 8, 9, or 10 as their next card value (remember that 10 can be achieved four ways).

P(bust with sixteen) = P(6) + P(7) + P(8) + P(9) + P(10)
P(bust with sixteen) = 1/13 + 1/13 + 1/13 + 1/13 + 4/13
P(bust with sixteen) = 8/13 ≈ 0.615

Now, we can determine the odds of busting with a fifteen. They could either hit and get a 7, 8, 9, 10, or an ace followed by a bust.

P(bust with fifteen) = P(7) + P(8) + P(9) + P(10) + [P(A) • P(bust with sixteen)]
P(bust with fifteen) = 1/13 + 1/13 + 1/13 + 4/13 + [1/13 • 8/13]
P(bust with fifteen) = 99/169 ≈ 0.586

We could then figure it out for busting with a fourteen. They could either hit and get a 8, 9, 10, ace-bust, or two-bust.

P(bust with fourteen) = P(8) + P(9) + P(10) + [P(A) • P(bust with fifteen)] + [P(2) • P(bust with sixteen)]
P(bust with fourteen) = 1/13 + 1/13 + 4/13 + [1/13 • 99/169] + [1/13 • 8/13]
P(bust with fourteen) = 1217/2197 ≈ 0.554

This process can be continued until you get to the probability of busting with a seven, which ends up being around 0.262. All of the probabilities of the dealer's outcomes with certain face up cards are on the table below:


So the chances of our sixteen beating the dealer's seven if we stand is 0.262; the only way we would win is if the dealer busts. If we hit, then we have a good chance of busting but also a chance of getting a number between 17 and 21, each with their own chance of winning.

P(win with an A) = P(dealer busts) + ½P(dealer gets 17)
P(win with an A) = 0.262 + ½(0.369)
P(win with an A) = 0.447

P(win with a 2) = P(dealer busts) + P(dealer gets 17) + ½P(dealer gets 18)
P(win with a 2) = 0.262 + 0.369 + ½(0.138)
P(win with a 2) = 0.730

P(win with a 3) = P(bust) + P(17) + P(18) + ½P(19)
P(win with a 3) = 0.262 + 0.369 + 0.138 + ½(0.079)
P(win with a 3) = 0.809

P(win with a 4) = P(bust) + P(17) + P(18) + P(19) + ½P(20)
P(win with a 4) = 0.262 + 0.369 + 0.138 + 0.079 + ½(0.079)
P(win with a 4) = 0.886

P(win with a 5) = P(bust) + P(17) + P(18) + P(19) + P(20) + ½P(21)
P(win with a 5) = 0.262 + 0.369 + 0.138 + 0.079 + 0.079 + ½(0.074)
P(win with a 5) = 0.963

P(win with a 6, 7, 8, 9, 10, J, Q, K) = 0

Now that we have all of this, let's do an expected value equation to see what our average odds are.

EV(hit on 16) = (1/13)(0.447) + (1/13)(0.730) + (1/13)(0.809) + (1/13)(0.886) + (1/13)(0.963) + (8/13)(0) = 0.295

So hitting on 16 gives 0.295 odds while standing gives 0.262 odds. And surprisingly enough, the hitting odds do end up better. Yes you are likely to bust when you hit, but it is better than banking on the worse odds of the dealer busting. The strategies for all of the other things can be derived in similar ways.

Next week, we will complete our series on the Gambler's Ruin Problem and see if video poker can offer odds as good as blackjack.

Saturday, February 8, 2014

Gambler's Ruin Problem Part 2: Odds in Craps

Click here to see part 1 of this four week series.



This week is week two in a four week series on the Gambler's Ruin Problem. Unlike my series on the proof to Bertrand's Postulate, this one can be started in the middle if you have an understanding of some elementary probability concepts like expected value. It will take away some of the initial surprise when faced with the probability of success in previous games, but it is not like Bertrand's Postulate where I am recalling or building upon information that was developed in an earlier post. They are all very separate pieces of information that can be understood on their own or together as an attempt at the Gambler's Ruin Problem.

The idea of the Gambler's Ruin Problem is simple. Here is the problem if you have forgotten it:

Suppose that you find yourself in a city with a casino and you have $60 in your pocket. There is a concert in town that you really want to see, but the tickets cost $100. You decide that you will place $1 bets until you either reach $100 or go broke. Which casino game should you play? How likely are you to reach your goal of $100?

Last week, we discovered that roulette loses on average 5.3¢ per dollar bet, which gives you a shockingly low 1.3% chance of reaching your goal of $100.

Game Avg Gain Per $1 Bet P of Reaching $100
Favorable Game (51-49 odds) 92.6%
Fair Game (50-50 odds)
60%
Roulette
-5.3¢
1.3%
Note: I added a 51-49 "favorable game" and its statistics. This was not discussed last week, but it is more informative for our needs than a 100% probability game like we discussed last week. It has a 2¢ average gain and a 92.6% success probability.

We have found all of the necessary data with roulette, and odds didn't look great. So let's try another game. This week we will look at craps, which is one of the most popular casino games involving dice.


The rules of craps take a couple minutes to remember in its entirety, but are pretty easy to understand.  This explanation comes from bigmcasino.com, which laid them out very well.
The players take turn rolling two dice. The player that is rolling the dice is considered the shooter. The shooter MUST bet at least the table minimum on either the pass line or the don’t pass line.
The game is played in rounds consisting of two phases: come out and point.
Come Out – to start a round, the shooter makes a “come out” roll
If the come out roll is a 2, 3, or 12, then the round ends. The rules of craps state that the shooter is said to “crap out” and players lose their pass line bets.
If the come out roll is a 7 or 11, this results in a win for pass line bets.
The shooter continues to make come out rolls until he rolls 4, 5, 6, 8, 9, or 10. This number becomes the point and in turn the point phase begins.
Point – during this phase, if the shooter rolls a point number then it’s a win for the pass line bets. If the shooter rolls a seven, it’s a loss for the pass line bets and the round is over.

There are many different bets that can be made in craps, but each can be analyzed through probability. I don't have nearly enough time and energy to go through them all, but I will discuss a few.
The most common craps bet is the pass line bet. This is the one discussed in the rules that wins on a seven, eleven, or the roll of the point number. To figure out its odds, we can just create a table of percentages for each of the eleven possible dice totals, determine the probability of winning the pass line bet, and perform an expected value equation like we mastered last week.
Come Out Roll Odds for Pass Line
2 0
3 0
4
5
6
7 1
8
9
10
11 1
12 0

I have already put in the ones that we know from the craps rules. The other six become point rolls and need to appear before a seven. Here are the possible roll totals from two dice:


Let's start with determining the odds for four. There are three ways to roll a four, six ways to roll a seven, and twenty-seven ways to roll something else. To determine the odds of success with a four, there are a few different methods. We will use a more logical method the first time, and then discover a quicker method to figure out the rest.

To roll a four before a seven, you must add up the probabilities of rolling it on the first try, rolling something other than a four/seven on the first and a four on the second, rolling something else on the first two and a four on the third, and so on. 

Rolling a four on the first try would be simply 3/36. Rolling something else on the first try (27 possibilities) and a four on the second try, the odds would be (27/36)(3/36). Rolling something else the first two times and a four on the third would be (27/36)(27/36)(3/36), or (27/36)2(3/36). Rolling something else on the first three times and a four on the fourth would be (27/36)(27/36)(27/36)(3/36), or (27/36)3(3/36). This pattern will continue forever.

Adding this infinite series up will give the following:

3/36 + (27/36)(3/36) + (27/36)2(3/36) + (27/36)3(3/36) + (27/36)4(3/36) + ...
(3/36)(1 + 27/36 + (27/36)+ (27/36)+ (27/36)+ ...)
(3/36)(36/9)
1/3

So your probability when rolling a four is 1/3. That way was the most direct way to calculate it, but also a little complicated and requiring some basic knowledge of infinite series. A much easier approach would be to realize that the remaining 27 options have no significance as to your success. There are 3 good rolls and 6 bad rolls and that is all that matters.

So out of the nine total significant rolls, three of them are winners. Using this logic, the odds for success would be 3/9, or 1/3 as discovered before. Either method generates a 1/3 chance of success.

Using the approach we just discovered, we can very quickly determine the odds for the other totals and complete the table from before.

Come Out RollOdds for Pass Line
20
30
41/3
52/5
65/11
71
85/11
92/5
101/3
111
120

This could then be used to determine the probability of winning the pass line bet. Keep in mind that it is not averaging the eleven totals, but multiplying their odds by roll frequency.

(1/36)(0) + (2/36)(0) + (3/36)(1/3) + (4/36)(2/5) + (5/36)(5/11) + (6/36)(1) + (5/36)(5/11) + (4/36)(2/5) + (3/36)(1/3) + (2/36)(1) + (1/36)(0) ≈ 49.293%

There is about a 49.293% chance of winning the pass line bet. Let's see what our expected value is when we make a dollar bet.

EV($1 bet on pass line) = 0.49293(1) + 0.50707(-1) = -1.4¢

A pass line bet in craps has an average loss of 1.4¢, which is much better than the 5.3¢ loss we continued to see in roulette. But are there other bets in craps that beat that?

Another bet in craps is called the don't pass line. This is pretty much betting that the shooter will lose rather than the shooter winning. Seems fair, right? It actually seems pretty favorable. But before you bet your mortgage payment on it, keep in mind one little rule. If the shooter rolls a twelve on his come out roll, then it is a push. In other words, a roll of twelve will not be included in the table or equations.

Come Out RollOdds for Don't Pass Line
21
31
42/3
53/5
66/11
70
86/11
93/5
102/3
110
(1/36)(1) + (2/36)(1) + (3/36)(2/3) + (4/36)(3/5) + (5/36)(6/11) + (6/36)(0) + (5/36)(6/11) + (4/36)(3/5) + (3/36)(2/3) + (2/36)(0) ≈ 47.929%

EV($1 bet on don't pass line) = 0.47929(1) + 0.52071(-1) = -4.1¢

With this minuscule adjustment of pushing a twelve, this bet actually becomes less favorable than the pass line bet. Rather than losing 1.4¢ on average, you would lose 4.1¢. Still better odds than roulette, but why bet against the shooter when you are benefiting more by betting for him?

There are many more bets in craps that I don't have the time to go through, but I would encourage you to perform the calculations with some of them. If you play craps at the casino, try taking one of your favorite bets and see if it measures up to the pass line bet or other options either within craps or in other casino games. Here are a few different options:

Place Bets are bets on a specific number. After the come out roll, if your number appears before a seven, you win the bet. Place bets on a six or eight pay 7:6, bets on a five or nine pay 7:5, and bets on a four or ten pay 9:5.

Place to Lose Bets are bets against a specific number. After the come out roll, if a seven appears before your number, you win the bet. Place to lose bets on a six or eight pay 4:5, bets on a five or nine pay 5:8, and bets on a four or ten pay 5:11.

Buy Bets are like place bets, except the casino gives you better odds in exchange for a 5% commission fee for making the bet. For instance, a $1 bet would be split where about 4.76¢ go to the casino and 95.24¢ go towards your bet. Buy bets on a six or eight pay 6:5, bets on a five or nine pay 3:2, and bets on a four or ten pay 2:1.

Lay Bets are like place to lose bets, except the casino gives you better odds in exchange for a 5% commission fee for making the bet (see buy bets). Lay bets on a six or eight pay 5:6, bets on a five or nine pay 2:3, and bets on a four or ten pay 1:2.

Hard Way Bets are bets on a specific pair (either two 2's, two 3's, two 4's, or two 5's). After the come out roll, if your pair appears before a seven, you win the bet. In the United States (and most other countries) hard way bets on a pair of twos or fives pay 9:1 and bets on a pair of threes or fours pay 7:1.

Hop Bets are bets on a specific combination of numbers (1&4, 3&5, 2&2, etc.), but they only last for one roll. During the point rolls, you can make a hop bet for that turn. If you get your combination, you win. If you don't, you lose that money. Hop bets on a combination with two different numbers (such as 1&4 and 3&5) pay 15:1 and bets on a pair (such as 2&2 and 4&4) pay 30:1. This is different from a hard way bet because the hop bet lasts for one turn while the hard way bet lasts until the shooter gets a seven.

There are still even more bets such as odds bets and proposition bets, but these should be a good start. The most common craps bet is the pass line bet, so we will use this when comparing casino games. Our table of games now looks like:

GameAvg Gain Per $1 BetP of Reaching $100
Favorable Game (51-49 odds)92.6%
Fair Game (50-50 odds)60%
Craps-1.4¢28%
Roulette-5.3¢1.3%

If you find some craps bets or combinations of bets (ex: pass line/odds - odds bets cannot be placed on their own) that have better odds than the ones we've discussed, please comment your insights. Probability in casino games is always a fun area of mathematics to discuss and debate about.

Saturday, February 1, 2014

Gambler's Ruin Problem Part 1: Odds in Roulette

When I was at MAAthFest (a mathematics conference run by the Mathematical Association of America) last summer, I got to spend the first two days in a short course on the Mathematics of Games and Puzzles put on by Dr. Arthur Benjamin, who is actually my mentor in learning mental math. He recently came out with a video course through the Great Courses on the Mathematics of Games and Puzzles, which you can click here to see or purchase.

Last month, we did a four week series on Bertrand's Postulate. It was a fun and interesting proof, but it did require some hard concentration as well as relatively heavy algebra, number theory, and combinatorics. So, I thought looking at a lighter and more practical problem might be a good idea. It is certainly still deep and thought-provoking, but it won't require as much higher-level mathematics. This problem is called the "Gambler's Ruin Problem," and we spent a lot of time discussing it in that short course. This problem goes as follows:

Suppose that you find yourself in a city with a casino and you have $60 in your pocket. There is a concert in town that you really want to see, but the tickets cost $100. You decide that you will place $1 bets until you either reach $100 or go broke. Which casino game should you play? How likely are you to reach your goal of $100?

This problem can go on forever because there are so many casino games, each one with different betting options and strategies and variations. But it is also a really fun problem, because throughout the process of figuring it out, you will learn a lot about how to improve your skills at the casino. Though probability shows that you likely won't make money, you will learn ways to play for a longer period of time without going broke. And if you use these strategies enough times, you might just get lucky. As a side note, I find it ironic that I as a fourteen-year-old am choosing to write blog posts about casino games.

There are too many casino games to fully analyze in just a few posts, but we do have time to take a look at some of the most popular. This week, we will focus on roulette. Next week will be craps. February 15th will be blackjack. February 22nd will be video poker (I would have probably preferred to do Texas Hold'em, but there is so much strategy, bluffing, reading players, and chance involved that it would be way above my head to analyze odds in that game). Notice that I am choosing to ignore slot machines. This is because they are one of the worst bets one can make in the casino. Just look at the rearrangement of the letters!

SLOT MACHINES
CASH LOST IN 'EM

So now let's start our basic analysis of roulette.


I'm sure many of you know the rules of roulette already, but I will quickly try to explain them to refresh everyone's memory. Though roulette can be played by many people at once, the game itself is just you against the house. Each spin of the wheel (at the bottom right corner of the picture above) is a game. The wheel is numbered from 1 to 36 with alternating red and black numbers. There is also a green zero as well as a green double-zero. The objective is to correctly guess a characteristic of the slot that the ball falls in to, whether it be the color, number, size, or parity (odd/even). Bets are placed on the green felt table, as shown more clearly in the picture below.


One of the more popular roulette bets is to bet on a color, say betting red. This bet pays evenly; you risk one dollar to gain one dollar (or whatever money amount you choose). When you bet red, there are 18 red numbers out of 38 total numbers, giving an 18/38 or 47.3% chance of winning.

To figure out how worthwhile this bet is, we do something called finding the expected value, which I discussed in my post about the Saint Petersburg Paradox. Expected value is essentially a weighted average; you average together your winning payoff and your losing payoff with the odds of achieving each one taken into account. For this example, winning a $1 bet would earn you 1 dollar and losing a $1 bet would cost you 1 dollar, or earn you -1 dollars. So, the calculation would be set up as follows:

EV($1 bet on red) = (18/38)(1) + (20/38)(–1) = -2/38 ≈ -0.0526316

In other words, each $1 bet on red will lose you 5.3¢ on average. Let's look at another bet, say betting on the first twelve numbers. This bet pays 2 to 1; you risk one dollar to gain two dollars. But, the odds of landing on one of those twelve are now 12/38 instead of 18/38.

Setting up the expected value equation gives us:

EV($1 bet on 1st 12) = (12/38)(2) + (26/38)(–1) = -2/38 ≈ -0.0526316

Again, the answer comes out to -2/38, or an average 5.3¢ loss. What if we were to place a bet on a single number. Let's say we bet on 26, the only natural number that is directly between a square (25 = 52) and a cube (27 = 33).  Casinos pay 35 to 1 on this bet; you risk one dollar to gain thirty-five dollars. The odds of landing on the number 26 would be 1/38. This expected value calculation would be:

EV($1 bet on 26) = (1/38)(35) + (37/38)(–1) = -2/38 ≈ -0.0526316

The answer is the same again: an average loss of 5.3¢. In fact, casinos choose the ratios for roulette such that every bet is the same expected value. Because of this, it does not matter to them what the players choose to bet on. They will always be making the same amount of money on average.

Let's return to the Gambler's Ruin Problem, and see how likely these odds are to achieve the $100. We mentioned before that the odds for winning with a bet on red is 47.3%. Though the odds differ with other bets, the properties of expected value end up making the game of roulette come out to a 47.3% chance of success. In other words, really close to 50-50, but just a hair below.

With the Gambler's Ruin Problem, a game with 0% odds would give 0% chance of success. A game with 100% odds would give 100% chance of success. Since you are starting with $60, a game of 50% odds actually gives a 60% chance of success. With a fair game, your amount of starting money determines your success interestingly enough.

What about a game of 47.3% odds? Would it be above 50% or below 50%? Sounds like it would be around that neck of the woods, considering that a 50-50 game gives a 60% chance. Turns out that there is a formula for determining the probability of turning $60 into $100.

Let p = probability of winning the game (in decimal form)
Let q = probability of losing the game (in decimal form)

Plugging 0.473 in for p and 0.527 in for q predicts the probability of success to be about 1.3%. This was really surprising to me at first. Just that 2.7% difference between fair and unfavorable costs you so much when it comes to succeeding in the Gambler's Ruin Problem. But probability is full of surprises, as you can see in my past probability posts as well as the posts in the rest of the month.

Saturday, December 14, 2013

Math in the News: The Influences of Politics

Though mathematics is normally a pretty concrete subject, people's intuition for it is not. Probability and statistics in particular is a very difficult area for us to grasp, as you've seen with the Monty Hall Problem I talked about a few weeks ago.

Here is another example of mathematical aptitude being influenced by an outside source, but this time, it is not just a matter of lack of skill or desire to be correct. It is also influenced sometimes by political views, as Kevin Drum shows in this news article. Check it out!

http://m.motherjones.com/kevin-drum/2013/09/politics-destroys-math-ability

Saturday, November 23, 2013

The History of the Monty Hall Problem

One of my very first blog posts was about the Monty Hall Problem. This is an extremely classic example of a probability paradox. Let me quickly describe the problem:
Pretend you are on a game show, and the host gives you three doors to select from. One of these doors has a car behind it, while the other two have goats. Let's say you select door number one. Then, the host (who knows where the car is) opens another door to reveal a goat. Let's say he opens door number three. You are then given the option to either stick to door one or switch to door two. Does either strategy have an advantage?

The common answer would be that it is 50-50, and there is no advantage either way. However, the correct answer is that there is only a 1/3 chance of winning by staying put, and a 2/3 chance of winning by switching. Click here to learn why.

This problem was first posed by Steve Selvin, but it was popularized by Marilyn vos Savant in 1990. Vos Savant is famous for once having the highest IQ in the world, as well as her "Ask Marilyn" column in Parade Magazine.

One week, her column was about the Monty Hall Problem. She posed the question, and then explained her reasoning as to why there is a 2:1 advantage for switching. This created a pandemonium of angry readers who insisted that she was incorrect, and furthermore, accused her of adding to the problem of innumeracy and lack of mathematical intuition in America. Some of these complaints came from a statistician at the National Institutes of Health, the deputy director of the Center for Defense Information, and professors at George Mason University, University of Florida, University of Michigan, Millikin University, Georgetown University, Dickinson State University, Western State College, and more. Even the legendary Paul Erdős couldn't wrap his brain around the paradox.

This problem has continued to baffle everyone it encounters, from average people to accomplished mathematicians. In 2010, Walter Herbranson and Julia Schroeder of Whitman College performed an experiment to see if playing the game multiple times could end up refining the player's strategy. The human test subjects failed to revert to the optimal strategy and switch doors in the experiment. However, when the test was performed on pigeons, with mixed grain as the prize, they were able to pick up on the fact that switching doors gave them the best chance of success. The fact that a pigeon can do better than a human in this situation is fascinating to me.

The Monty Hall Paradox is something that reminds us of how humans are not wired to understand probability and statistics. This is why people can be fooled by mathematical scams and why casinos are packed full of gamblers. If our math curricula put an equal focus on probability and statistics as it did on algebra and calculus, then our world would have much better math minds and critical thinkers in general.

Saturday, March 16, 2013

Benford's Law

Take any random quantity. Maybe a population of a city, a mass of a planet, a distance from a star, or an amount of twitter followers. Now, take the first digit of this number. What are the odds that it will start with a 1, or a 2, and so on?

One would think that it would be a one in nine chance for each digit. If you are randomly selecting this number, the first digit is just a random number selection between one and nine.

However, this reasoning does not work. Try finding these quantities yourself. Or, just go to http://testingbenfordslaw.com. If you check all of the different areas that are possible, you will see that the smaller the digit, the more commonly it appears.

Here are the approximate odds for each digit:

1: 30.1%
2: 17.6%
3: 12.5%
4: 9.7%
5: 7.9%
6: 6.7%
7: 5.8%
8: 5.1%
9: 4.6%

Since this is a math blog, something we would want to do is find a pattern between these numbers. This could probably be done on a graphing calculator, using similar techniques to the post on data analysis.

It is clear that a line of best fit would not be the solution. If we connected the points with a curved graph, it would look like this:


You can see that this graph gets really close to the y-axis, but it does not seem to touch it. Similarly, it gets really close to the x-axis, but doesn't touch it. Thus, the x and y-axes would be called asymptotes of this graph.

But, an asymptote could be found in a rational function, radical function, exponential function, logarithmic function, hyperbolic function, trigonometric function... So, it is hard to define this graph solely based on the presence of asymptotes.

The function that does work with this graph is a logarithmic one. A logarithm is basically the opposite of an exponent. For instance:

52 = 25
log5(25) = 2

Just knowing that the equation is logarithmic doesn't seem to narrow it down a lot, because there are so many different types of logarithms. However, there are three types which are seen the most frequently. In fact, most scientific calculators contain just these three types.

Logarithm Type BaseSimple Notation Standardized Notation Applications
Natural Logarithm
e (the irrational number ≈ 2.71828)
loge(x)
ln(x)
Calculus, Statistics, Physics, Chemistry, Economics
Common Logarithm
10
log10(x)
lg(x)
Algebra, Engineering, Geology, Spectroscopy, Music
Binary Logarithm
2
log2(x)
lb(x)
Discrete Mathematics, Computer Science, Information Theory

If we confine the possible equations to one of these, it narrows it down a lot. And this assumption is correct. The equation that the graph fits is:

y = lg(1 + 1/x)

(Remember that x is the starting digit and y is the percentage for that digit)

I was pretty surprised about this equation. But, all of the percentages listed above are the outcome of this equation.

Benford's Law can be used in biology, accounting, law, economics, etc. However, a more fun way to use it is to turn it into a game.

Tell someone that you will get the numbers 1, 2, and 3 and they will get the numbers 5, 6, 7, 8, and 9 (and nobody gets 4). You then have them come up with random quantities that they wouldn't know, and you look up the number (you can use Google or WolframAlpha for this). Every time it is a 1, 2, or 3, you win a point and every time it is a 5, 6, 7, 8, 9, they get a point. They think they have around a 2:1 advantage over you, but you are really the one with the 2:1 advantage.

Click here to see this game played on the show Scam School.

Saturday, January 19, 2013

Game Theory and Soccer

When I gave my TEDx talk in India this past December, one of the things I talked about was an application of game theory to soccer. Since I think it is pretty cool, I thought I would share it.

You may know that a penalty kick is when a player gets a free shot at goal from a point about 12 yards (or 11 meters) from it with only the goalkeeper allowed to block the shot. Since this is such a close distance, the goalie just has to take a guess as to whether the kicker will shoot to the left or the right. The kicker also has to choose to kick to his left or his right, since kicking to the center is kicking right to the goalkeeper.

So, we know what each player's strategies are. Let's create a grid to represent it, like we do in most game theory examples.

Dive LeftDive Right
Kick Left

Kick Right



Next, we need to figure out what percent of the time the kicker scores in these four outcomes. So, a professor from the London School of Economics named Ignacio Palacios-Huerta figured these statistics out by taking data from over 1400 penalty kicks. This was his result:

Dive Left Dive Right
Kick Left  .58, .42   .95, .05
Kick Right  .93, .07     .7, .3

Now, we will use some game theory techniques to figure out what the optimal strategy of each player is. In this case, it would be best to find the mixed-strategy equilibrium

Goalkeeper's Optimal Strategy (Diving Left)
.58x + .95(1 - x) = .93x + .7(1 - x)
.58x + .95 - .95x = .93x + .7 - .7x
.95 - .37x = .23x + .7
.25 = .6x
.42 ≈ x

Kicker's Optimal Strategy (Kicking Left)
.42x + .07(1 - x) = .05x + .3(1 - x)
.42x + .07 - .07x = .05x + .3 - .3x
.35x + .07 = .3 - .25x
.6x = .23
x ≈ .39

So, the goalie's optimal strategy is to dive to the left 42% of the time and the kicker's optimal strategy is to kick to the left 39% of the time.

This alone is pretty cool, that we can determine the best way for a soccer player to handle this situation. However, we don't know if this actually works. So, Ignacio Palacios-Huerta took data from the best kickers and goalies in the world to see how their strategies matched up with the math.

Surprisingly enough, they were using the exact same strategy. The fact that even though these soccer players don't know game theory, but happened to stumble upon this perfect strategy was really impressive.

Bonus: While on the topic of game theory in soccer, I thought I would mention a famous soccer game that involved some game theory. In the 1994 Caribbean Cup, Granada faced Barbados. Because of some unique rules, a very interesting thing happened. Click here to read the Wikipedia article about the match.

Saturday, December 8, 2012

Game Theory Made Easy: The Criss-Cross Method

A couple weeks ago, we discussed the Criss-Cross Method for multiplication as a way to make it much easier when we get into larger numbers. The traditional method seemed easy, but in reality, it wasn't so easy.

Before I begin, let me mention a quick thing about game theory. Back when I did my four posts on finding game theory strategies, I gave examples of what are called non-zero sum games. These are games where the two players' payoffs do not add to a consistent sum. For instance, in the game between the police and the criminals, we ran across these payoffs.

CrimeLay Low
Patrol
3, -5
0, 1
Donuts
-2, 3
2, 0

If you look in each box containing numbers, you will see that the sums are all different.

3 + (-5) = -2
0 + 1 = 1
-2 + 3 = 1
2 + 0 = 2

However, any game you can quickly think of probably does have a consistent sum. Though the card game war is not a true mathematical game (it is not strategic), I will use it for an example.

Every time you put down a card, you either have a card that is higher, lower, or equal to your opponent's card. If it is higher, you keep your card and win their card (a payoff of 1) and your opponent loses their card (a payoff of -1). Same goes vice versa, you lose your card (a payoff of -1) and they win your card (a payoff of 1). If it is a draw, you do war, which makes you put down four more cards in addition to the original one; three face-down cards and one that you use for the actual war. If you win the war, you win five cards (a payoff of 5) and your opponent loses five cards (a payoff of -5), and vice versa.

If you'll notice, in every instance, your payoff is the additive inverse, or the negative of your opponent's payoff. This seems to be rare, but most games are actually like this. These are called zero-sum games, because in every scenario, you and your opponent's payoffs sum to zero.

Back to what I wanted to say today, game theory has something as well that is completely impractical in certain situations. Namely, the method to find mixed-strategy equilibria. It is already fascinating, but the game theory Criss-Cross Method is much more efficient.

Let's take the following fictional example. Say Bob and Joe are playing a game of tennis, and Bob is serving. Bob can choose to serve to the left side of the court or the right side of the court. Joe can choose to position his body weight so that he is ready for a serve coming to the left side, the right side, or just wait and see where it ends up.

Bob has a very strong serve going to the left, and Joe knows this. So, these made-up payoffs are what the odds (in percent form) are that Bob and Joe will win the match:


Prepare LeftPrepare RightWait Until Serve
Serve Left
60, 40
90, 10
       80, 20
Serve Right
80, 20
30, 70
       50, 50

These don't look like zero-sum payoffs. However, I mentioned earlier that a zero-sum game is a game whose sums are consistent, but they actually don't have to be zero. In this case, the payoffs sum to 100.

The next thing we would have to do now is narrow this down from a 2xn game to a 2x2 game. There is a graphing method that I don't have the time to explain right now that will narrow it down for us. The basic purpose of it is to see if there are any of Joe's strategies where no matter what strategy Bob uses, there will be another strategy better than it. In this case, Joe is always better off preparing one way than just waiting until the serve. So, "Wait Until Serve" is a dominated strategy, or it is a strategy that can always be beaten by another one.

Just to simplify the game a little bit, I will divide each number by ten and then subtract five from them. This will make it more like a common zero-sum game.

Prepare LeftPrepare Right
Serve Left
1, -1
4, -4
Serve Right
3, -3
-2, 2


A zero-sum game in this notation can be written with just player one's, or Bob's, payoff in the boxes, and then the analyst can conclude the other player's payoff. Let's write it that way for simplicity's sake.


Prepare LeftPrepare Right
Serve Left
1
4
Serve Right
3
-2



Now, we would normally go about our regular algebra. Let me do it out here:

Bob's Strategy:

(-1)x + (-3)(1 - x) = (-4)x + (2)(1 - x)
-x - 3 + 3x = -4x + 2 - 2x
2x - 3 = 2 - 6x
8x - 3 = 2
8x = 5
x = 5/8


Serve to the left 5/8 of the time and to the right 3/8 of the time.

Joe's Strategy:

(1)x + (4)(1 - x) = (3)x + (-2)(1 - x)
x + 4 - 4x = 3x - 2 + 2x
4 - 3x = 5x - 2
4 = 8x - 2
6 = 8x
6/8 = x

Prepare left 6/8, or 3/4 of the time and right 2/8, or 1/4 of the time. Never make your decision after the ball is served.


Okay, that was complicated. Imagine if we never simplified the game. But the Criss-Cross Method would have made this a lot easier. For Bob's strategy, we would find the absolute value (distance from zero) of the difference of his possible payoffs for serving left. We would do the same thing for his payoffs for serving right.

Serving Left: | 1 - 4 | = | -3 | = 3
Serving Right: | 3 - (-2) | = | 5 | = 5

If we add those together, we get the common denominator used for their probabilities. 3 + 5 = 8, so the probability will be out of eight.

How do we find the numerators? Simply flop the three and the five, or criss-cross them. This will give you 5/8 for serving left and 3/8 for serving right, which is the same as the algebra.

Same thing for Joe, except we go vertically now.

Preparing Left: | 1 - 3 | = | -2 | = 2
Preparing Right: | 4 - (-2) | = | 6 | = 6

Add these together, and we get a common denominator of eight. Now, criss-cross the 2 and 6 to get 6/8 of the time preparing left and 2/8 preparing right. Same as before.

It might seem a little weird at first as to why on earth that would work, which I don't have a clue about. Please comment if you do know why it works.

I probably made it look more complicated than it is with the example I used. However, I wanted to keep the post practical, and you won't find people talking about payoffs of four in life. In fact, you probably won't hear the success statistics in real life. A game theorist would have to take data of both players and determine the statistics. However, the process after must be completed before you actually get down to the criss-cross method at the end. But it is a really cool way to finish off the problem.

Saturday, August 25, 2012

How to Win Games Part 4: Counter Prudential Strategies

Last week, we talked about how to counter someone who plays spitefully by using your prudential strategy. However, what if you know someone is playing prudentially?

This week, we will conclude the four game theory posts by learning how to determine your counter prudential strategy, which does exactly what it says: counters the prudential strategy.

First, you will have to figure out their prudential strategy though. Let's go back to the police-criminal game from last week.

Crime Lay Low
Patrol
3, -5
0, 1
Donuts
-2, 3
2, 0

We had determined that the police's prudential strategy is 4/7 patrol and 3/7 donuts. So, what do the criminals do?

Well, this isn't their mixed-strategy equilibrium. Remember that the mixed-strategy equilibrium is a way to make the other player's payoffs equal so that they don't have an advantage by playing one way or another.

Since this is the prudential strategy, and therefore not the mixed-strategy equilibrium, the criminals do have an advantage by playing one way or another. So, let's determine the expected payoff of playing either strategy.

For committing crime, they will get -5 4/7 of the time and 3 3/7 of the time. So, we do:

-5(4/7) +3(3/7) = -11/7

For laying low, we do the same thing:

1(4/7) + 0(3/7) = 4/7

Since 4/7 is greater than -11/7, the criminals should lay low every single time for their counter prudential strategy.

Though this type of thing isn't a proof or pattern like I normally post about, I find it really cool that you can analyze games just like you analyze math. If you have a lot more time, you can analyze games like chess, poker, black jack, and even sports.

Answer: Here is the answer to July's problem of the week. Make sure you do last week's as well!

Easy:
e = 24
h = 30
m = 12
n = 18
A = 81

Hard:
t = 45
z = 4.5
s = 50
a = 1
b = -1250
c = 390625
x = 625
P = 50Ï€

For the rope problem from the hard problem of Monday, you must first set both ends of one rope on fire and set only one end of the other rope. Half an hour later, your first rope has burned completely leaving your second rope with 30 minutes left. Now, set the other end, and put your plant over the flame for its fifteen minute cooking.

Saturday, August 18, 2012

How to Win Games Part 3: Playing it Safe

For the last couple of weeks, I have been showing how to incorporate some game theory into daily life, and choose what the best strategy is, which isn't always what it seems like. As you saw last week, the police can get away with patrolling very little because the criminals are risking such a loss by committing crime.
By playing the way we learned last week, we are playing less to make ourselves win and more to make the other player lose. We make their payoff at the bare minimum of what we can get away with so we have a better chance of winning. This is called playing spitefully.
What if you think the other player is playing spitefully? What do you do?
You could play spitefully as well. If you use the same logic, you can actually determine who will win the game. You determine both expected payoffs, and in some cases, you will be guaranteeing yourself a loss by playing spitefully.
Rather than playing spitefully back, you can use your prudential strategy, which is basically your best counter for spiteful play. And you solve for it almost the same way as solving for mixed strategy equilibria: what we learned last week.
Let's go back to the police and criminal game from last week.

Crime Lay Low
Patrol
3, -5
0, 1
Donuts
-2, 3
2, 0

Let's say you are the police, and you know that the criminal is playing spitefully. This means he is committing crime 2/7 of the time and laying low 5/7 of the time.

For the police's counter, you solve it by first realizing that the criminals are only using your payoffs to create their strategy. So, you can take that into consideration by pretending their payoffs are not what they are and instead the negative of your payoff (they want your payoff to be low, so they want the negative of yours to be high). The game then looks like this:


Crime
Lay Low
Patrol
3, -3
0, 0
Donuts
-2, 2
2, -2


This is called a zero sum game because if you add the two payoffs in each box, it equals zero.

Now, we solve for our mixed strategy equilibrium in this new game.

Police:

-3x + 2(1 - x) = 2 - 5x
0x - 2(1 - x) = 2x - 2

2x - 2 = 2 - 5x
7x = 4
x = 4/7

So, the police should patrol 4/7 of the time and eat donuts 3/7 of the time, which seems to make a little more sense. They are doing their job more often, and they will catch a lot more criminals.

But how does the criminal counter that? Shouldn't they shy away from committing crime then? Next week, we will conclude my game theory posts for now, and we will learn how to counter the prudential strategy.

Saturday, August 11, 2012

How to Win Games Part 2: Strategizing for Any Game

Today is part two of my game theory posts. Last week, we looked a game that had a saddle point, where there is a dominant strategy for each player. That made it fairly easy to solve, as each player should play a certain strategy every single time regardless of the other player's move.

Yet, not every game is so simple. Sometimes, there isn't a saddle point, and playing a single strategy will just make yourself predictable to the opponent. You need to mix it up, but not 50-50. That's predictable too. You need to determine how you should mix it up mathematically that will give you the best possible outcome.

For instance, let's look at the following game between the cops and the criminals. It is nighttime: the time the criminals commit crime. The police are trying to decide if they should go on patrol and try to catch criminals or socialize at the donut shop. The criminals are trying to decide if they should commit crime or lay low. The matrix would look something like this (assuming that the police are player one and the criminals are player two):

Crime Lay Low
Patrol
3, -5
0, 1
Donuts
-2, 3
2, 0

First, we said we would look for dominant strategies (formally called the pure strategy equilibrium), but there don't seem to be any. This sticks us with this 2x2 matrix that we have to solve for.

We will solve it with a mixed strategy equilibrium, where we figure out what probability we should play each strategy.

To do this, we first set our variables. Let's say that x of the time, we play patrol, meaning that 1-x of the time, we play donuts. Now, we must solve for the criminals' expected payoff for each of their strategies.

If the criminal commits crime:
-5(x) + 3(1 - x) = 3 - 8x

If the criminal lays low:
1(x) + 0(1 - x) = x

We want their expected payoffs to be equal (if they aren't equal, the criminals will just go for the higher of the two outcomes and receive more than they could have otherwise), so we will set the 3 - 8x equal to the x.

3 - 8x = x
3 = 9x
1/3 = x

Therefore, the police should patrol one third of the time, which may be surprising to you considering that donuts is risking a -2 while patrolling is only risking a zero.

The criminals can solve for their optimal strategy using the same logic:

Patrol:
3x - 0(1 - x) = 3x

Donuts:
-2x + 2(1 - x) = 2 - 4x

2 - 4x = 3x
2 = 7x
2/7 = x

The criminals should commit crime two sevenths of the time, which isn't as shocking, considering the risk of the -5.

This strategy works well, as you are making your opponent's outcome as low as possible. The problem is when you know your opponent is playing like this, you have no control over your own outcome. Regardless of how you play, you are going to get the same outcome. Your goal then becomes making your opponent's as low as possible so you can actually pull a win.

In game theory, this is called playing spitefully, where you are purposely trying to make your opponent's payoff low in order to win more easily. Next week, we will learn how to deal with spiteful players, and how to deal with players who think you are spiteful as well.

Answer: A little less than a month ago, I gave you the monk problem, which is another great puzzle. Here is the solution:

First off, remember how the head monk phrased it. There are "sinners" among us. This suggests that there are more than one. So, if you only saw one sinner, you would leave since you would be the second sinner.

The next day goes by, and there are still sinners. Now, if you saw two sinners, you would leave. This is because you know the other two would have seen each other and left unless they saw another sinner. You realize that you must have been that other sinner, and you leave.

The third day goes by and there are still sinners. Now, if you saw three sinners, you would leave. Same logic as before, you know that the three you saw would have left if there were truly three sinners. You then realize that you must be the fourth, and you leave.

Since there were no sinners on the fourth day, that means that there were four sinners, and they left on the third day because of the logic in the paragraph above.



Saturday, July 14, 2012

CTY: My Envelope Has More Than Your Envelope

This is my last week at CTY. In class, we looked at this problem:

Someone hands you an envelope and asks you to look at the contents (let's say it is some dollar amount). They then say that they are holding a second envelope that has either double of yours or half of yours. You must decide whether to switch envelopes or keep the one you currently have.

To solve this mathematically, you would use the expected value formula we used last week. Say your envelope has X dollars. You can either:

EV (Stay) = X
EV (Switch) = 1/2(1/2X) + 1/2(2X) = 5/4X

In other words, you will make 25% more money on average by switching. However, that is not realistic in these situations.

You must examine the problem from a logical standpoint. If you have a very generous person offering this deal and showing an envelope with $10, it might be worth the gamble to switch. If a more conservative person offered the same deal, you would be better off staying.  I found this problem cool because once again, math failed to give a reliable answer.

Bonus: Here is another problem to solve. I will give the answer in a month.

There are a group of monks who all vowed not to communicate to one another in any way (speaking, codes, sings, etc.). Every morning, the monks all gather in a circle and the head monk speaks to them.  One morning, the head monk said that there were sinners among them. He waved his hand and a mark appeared on all of the foreheads of the sinners (everyone knew who had marks, but could not see if they had one). He asked for anyone who knew they were a sinner to leave.

The second morning, the head monk announced that there were still sinners left and put the marks back. Once again, he asked for anyone who knew they were a sinner to leave.

The third morning, the head monk announced that there were still sinners left and put the marks back. For a third time, he asked for anyone who knew they were a sinner to leave.

The fourth morning, the head monk announced that all of the sinners had left.  How did the sinners know to leave?

Answer: A month ago, I posted the locker problem where student one opens every locker, student two closes every even locker, student three opens/closes every third locker, and so on up through 1000 students. The question was which lockers remain open.

The answers are:

1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961

There is a pattern among these 31 numbers: they are all square. The reason for this is that every non-square number doesn't just have factors, but they have pairs of factors. For instance, six has factors:

1 x 6
6 x 1
3 x 2
2 x 3

The six and the one can be written twice, giving it two factors. Therefore, six will get opened by 1, closed by 2, opened by 3, and closed by 6. However, a number like 9 has factors:

1 x 9
9 x 1
3 x 3

Here, the three cannot be written twice since it is paired with itself. So, locker nine will get opened by 1, closed by 3, and opened by 9. The same logic applies to all of the lockers.

Saturday, June 30, 2012

The St. Petersburg Paradox at CTY

This week, I am at my Johns Hopkins Center for Talented Youth Program, and I am taking Game Theory and Economics. Like last year, I wanted my post to be something cool I had learned that week.

First off, there is something called expected value, which means that if you do the experiment say millions of times and average all of your results, you will be extremely close to the expected value.  To determine expected value, you must multiply each outcome by the probability of that outcome occurring. Add all of those up and you have the expected value.

EV = P(a) x a + P(b) x b + ...

For a standard die roll, the expected value is:

EV = 1/6(1) + 1/6(2) + 1/6(3) + 1/6(4) + 1/6(5) + 1/6(6) = 3.5

So, the expected value is 3.5. Of course, you cannot get 3.5 on a single die roll, but if you average together a thousand rolls, you are sure to be near 3.5.

As an expected value problem to solve, our teacher gave us what is called the St Petersburg Paradox, which describes a mathematician who is told that he can play a game where he flips a coin until he gets tails. Afterwards, he will get 2^n pieces of gold, with n being the number of heads he flipped before he flipped a tails. The mathematician immediately went to determine the expected value, which is:

EV = 1/2(1) = 1/4(2) + 1/8(4) + ... EV = 1/2 + 1/2 + 1/2 + ... = infinity

This is saying that if you average all of your trials, you will get infinity. However, you have a fifty-fifty chance of getting just one piece. How can this be?

As I mentioned earlier, this is a paradox; it's mathematical answer differs from its logical answer. For a logical answer, you can cut it off at how much gold they are able to award him (they can't afford 2^50 pieces) and calculate. It still won't be very accurate until huge numbers of trials. Anyways, I found that pretty cool.

Bonus: We recently received a puzzle as well. As usual, I will provide the answer in a month.

By pure random guessing, what is the probability that you will get this answer correct.
  a. 50%
  b. 25%
  c. 0%
  d. 50%

Saturday, June 16, 2012

The Math of Your Locker

Since school just ended, my mind is kind of on clearing out my locker. So, I thought that for today’s post, I would talk about some math that deals with lockers.
First off, picking lockers. We usually have a locker combination to prevent thieves from breaking in. Some thieves can enter a locker combination in a second.
Let’s say you have three dials, each with a number from one to six on it. Your combination is three numbers between one and six. So, there are 6 x 6 x 6 possible combinations.
6 x 6 x 6 = 216
Pretend this thief went to your locker and tried every single combination. If they can do a second per combination, they will be getting in in under four minutes.
216 ÷ 60 = 3.6 = 3:36
Because of probability, it should only take half this time, meaning that a thief could break into your locker in under two minutes.
Don’t get scared. For a four dial locker with numbers from 1-10, it would take over an hour to break in. I just find it cool how small the numbers are for the three dial locker.
Secondly, I would like to share a problem I learned in fifth grade. As usual, I will post the answer in a month. This will be good practice for the problem of the week beginning on Monday.
There is a school with 1000 students and 1000 lockers. Student one runs through the school and opens every locker. Student two runs through the school and closes every second locker. Student three runs through the school and opens/closes every third locker and so on. If all 1000 students go through the school the same way, which lockers are left open. Is there a pattern they follow?

Our problem of the week is back! If you were not following Cool Math Stuff last summer, let me explain. In the summer, each month, I will create two very long problems: an easy problem and a hard problem. Problems so long that it takes five days to figure out the answer. Each day, I will post the next part of the problems for you to solve. After the five days, you will have a month to determine the answers. I will post the answers on the Saturday's post following the next month's problem of the week.

Last year, there was guidance with the problem. This year, I am going to make it a little more challenging. For June, there will be the same level of guidance as last year. July, I will be taking it down a notch. You will have some hints (maybe the important formulas, or some calculator buttons to look for), but no in-depth instruction like before. In August, it's all you. There will be a problem, and an answer the next September.

June's problem of the week will be given from 6/18 - 6/22.

Also, I gave you a KenKen puzzle a month ago (maybe a little more). Here is the answer: