March 23rd, 2012

Royal Flush in the Family

tl;dr Last month I was part of an event 6 times rarer than winning the MEGA Millions Lotto jackpot.

My grandfather played poker with a core group of friends (to my knowlegde he did not play in card rooms or casinos) and taught me the basics of the game. We played Five-card draw with penny antes. Those instances and the occasional occasional video poker machine summed up my poker experience until the recent Texas Hold’em craze that started with Chris Moneymaker‘s 2003 World Series of Poker victory and the explosion of online gambling. I learned the ropes of that poker variant and play with friends and in casinos when the opportunity arises.

A few years ago my grandmother asked me if I wanted any of my grandfather’s belongings (he had passed away several years earlier). I remembered a framed royal flush, signed and dated by witnesses (I’m not sure whether he was playing Five-card draw at the time, and if so how many of the royal flush cards he was dealt vs. exchanged).

IMG_20120323_081210

On February 28th I was in South Lake Tahoe for a company ski trip and sat down in the Harvey’s poker room with a couple of co-workers (no-limit Texas Hold’em, $2 small blind, $3 big blind). After playing for about an hour, our table of ten started to lose people, eventually becoming a table of five and disbanding. My co-workers moved to a table with two empty seats and I to a table with one (maximum of ten players per table).

After a few unworthy hands the dealer tossed KQ♠ (king and queen of spades) as my starting hand. I sat in fifth position. One person called and one folded in front of me, I called, two people called after me and both blinds joined in. With six players and $18 in the pot, the dealer flopped A♠K♦J♠. The blinds checked, the player in front of me bet $10. I called, the two players behind me called and the blinds folded. Four players left, $53 in the pot (dealer took $4 for the casino whenever the pot reached $40). The turn was 3♣. The person in front of me checked, I checked, the next person checked and then the last player bet $15. The player in front of me folded, I called and the player after me called. Three players left, $97 in the pot. The river was T♠. Holy cow, not only did I have a flush, but I had a royal flush, the highest possible hand in all of poker.

First to act and trying to keep my cool, I took a moment to consider my options. I could check, hoping one of the other two players would bet and then raise them. I could make a small bet, say $20-$30 and perhaps someone would call or re-raise me. Or I could make a sizable bet and it’s possible someone might think I was trying to buy the pot. The people remaining each had over $500 worth of chips in front of them and I had a little less than $200. I put out $75, about 75% of the pot and 40% of my stack in the hopes that someone else had hit something and thought I was attempting to buy the pot. The next guy thought for a while, but eventually folded and the other player quickly folded, oh well. I didn’t have to show my cards, but how could I not show a royal flush?

So I flipped over my cards and the table erupted. It also turned out the casino had a bonus jackpot which grew slowly based on the number of hands dealt and I received 5% of it for showing a royal flush. It wasn’t a boatload of money i.e. I learned the casino isn’t required to report payouts of under $600 to the government, but it was a pleasant surprise. I tipped the dealer about 10% of my bonus and then thought of my grandfather’s royal flush and asked if I could keep the deck of cards. The dealer quickly said that wasn’t allowed, gathered the cards and placed them in the shuffler as if nothing special had happened (he mentioned he had dealt a royal flush earlier in the day). I wanted my tip back.

I received some crappy cards for the next hand and immediately mucked them. As I finished stacking my winnings and lamented not having an item of memorabilia to go with my grandfather’s, not even a photo, something strange happend. The table erupted again as another player had just turned over a royal flush in hearts. The board had AKJT♥ (not sure about the fifth card) on it and they had Q♥ in their hand. This was a first for everyone on the table, including the dealer, two royal flushes in a row. People jokingly asked if the dealer was worried about getting fired, after all he had caused the casino to payout ~15% of the bonus today (he answered no).

My co-workers and I started wondering how often one could expect two royal flushes in a row during a game of Texas Hold’em. In the simplest scenario i.e. choosing 5 random cards from a standard 52 card deck, the odds of getting a royal flush are 1 in 649,350 hands. That number is generated via a branch of mathematics called Combinatorics. First one calculates the number of ways to select 5 cards from 52 (without replacing any during the selection process). There are 52 different ways 1 card can be picked from a deck, one for each card. That leaves 51 cards from which one can select another card, and after that card has been picked, 50 cards remain etc. So one might think the number of ways to select 5 cards from a 52 card deck is 52*51*50*49*48 = 311,875,200.

That calculation would be correct if one was looking for all the permutations of 5 card poker hands i.e. the order was important e.g. selecting A2358♣ was considered different from picking 35A82♣. In poker, combinations not permutations matter. Our original computation can be written using factorial notation i.e. 52!/(52-5)! = 52!/47!. It’s easy to work out with smaller numbers e.g. select 3 cards from a deck of 5 = 5*4*3 = 60 and 5!/(5-3)! = 5!/2! = (5*4*3*2*1)/2*1 = 60. In the case of choosing 3 cards from a deck of 5, one must also divide by 3! since any permutation works. As an example, for 3 items A, B and C there are 6 combinations, ABC, ACB, BAC, BCA, CAB, CBA . This is because there are X different items which can occupy the first position, X-1 for the next, etc. which leads to X!.

Getting back to the 5 cards out of 52 example our the number of possible 5 card hands in poker is 52!/(5!*(52-47)!) or 2,598,560. This is often written as (52 choose 5) and the math becomes N!/(K!*(N-K)!) for any (N choose K). There are 4 possible royal flushes so the odds of getting dealt one given 5 cards are 4 in 2,598,560 or 1 in 649,350. Given 7 cards as in Texas Hold’em, getting a royal flush of 5 cards should happen more often. The number of possible 7 card hands is (52 choose 7) = 133,784,560. If someone has a 5 card ace high straight flush, it doesn’t matter what the other 2 cards are, so we can simply multiply the number of different royal flushes, 4, by the number of ways to choose 2 cards out of the remaining 47 (52-5 since the 5 cards that make up a royal flush are already out of the deck). (47 choose 2) = 1,081, 4*1,081 = 4,324 making the odds 4,324 in 133,784,568 or 1 in 30,940.

At my poker playing peak, probably sometime in 2004 or 2005, I played online a few hours per week, at a friends house a few hours once a month and at a casino for a few hours once a year, so 3*52+3*12+3 = 195 hours of poker/year. If I saw 20 hands/hour, that’d be 20*195 = 3900 hands/year and I so perhaps I’d expect to get one royal flush roughly every 8 years.

But I hadn’t even witnessed a royal flush before; when playing at a table with multiple people, there is more than one 7 card hand happening at a time (often there are 8-10 players). So how often could I expect to witness a royal flush? One of my co-workers came up with this line of thinking. Royal flushes are unique in that no matter how many people are playing, only one person can have a royal flush per hand i.e. the probabilities for each additional player at the table getting a royal flush are mostly disjoint (mostly because if the royal flush appears in the 5 community cards, everyone at the table has a royal flush so that event should only be counted once). We’ve already calculated the odds of getting a royal flush given 7 cards, so for each additional player at the table (assuming they stay in to the river) the probability of witnessing a royal flush goes up by the probability of a single person getting a royal flush. Let’s set some variables:

  • RF5 = p(royal flush|5 cards) = probability of a royal flush given 5 cards = 4*(52 choose 5) = 0.00000154
  • RF7 = p(royal flush|7 cards) = probability of a royal flush given 7 cards = 4*(47 choose 2)/(52 choose 7) = 0.00003232
  • RFX = p(royal flush|X players at the river) = probability of a royal flush with X players at the river = X*RF7-(X-1)*RF5

For RFX the (X-1)*RF5 factor removes the over-counting when the community cards contain a royal flush. The probability of that event is RF5 and it occurs once in each RF7. So subtracting X-1 of them leaves one for everyone to share. Plugging in the numbers for X = 10 yields 0.00030934 or 1 in 3,233 hands.

In reality, the odds are much lower as ten people staying in for the river card at the same table does not happen often, if ever. In many cases, the hand is over before the turn or river card gets shown and if the river does come into play, only a few people remain in the hand. So if on average, one out of every three hands goes to the river and when that happens, on average three players remain RFX is more like RF7-(3-1)*RF5 = 0.00002924 or 1 in 34,200 hands.

My other co-worker attacked the problem in a slightly different way, by summing the three probabilities of various ways a royal flush can occur in a game of Texas Hold’em i.e. 3 of the 5 community cards and both of cards from a single player make a royal flush, 4 of 5 community cards and one card from a single player make a royal flush and when 5 of 5 community cards and 0 cards from every player make a royal flush. To compute the odds that way, let’s set some variables (these again all presume all players at a table stay in until the river every game):

  • C1 = p(1 royal flush card|royal flush, X players) = probability of a player getting the 1 card necessary to complete a royal flush given a royal flush is happening and X players are at the table = 2*X/(47 choose 1)
  • C2 = p(2 RF cards|royal flush, X players) = probability of a player getting the 2 cards necessary to complete a royal flush given a royal flush is happening and X players are at the table = X/(47 choose 2)
  • C3 = p(3 of 5|royal flush) = probability 3 of the 5 community cards are used by a player given a royal flush is happening = ((5 choose 3)*(47 choose 2))/(52 choose 5)
  • C4 = p(4 of 5|royal flush) = probability 4 of the 5 community cards are used by a player given a royal flush is happening = ((5 choose 4)*(47 choose 1)/(52 choose 5)
  • C5 = p(5 of 5|royal flush) = probability 5 of the 5 community cards are used by a player given a royal flush is happening = (5 choose 5)/(52 choose 5)
  • RFX = p(royal flush|X players at the river) = probability of a royal flush with X players at the river = 4*((C1*C4)+(C2*C3)+C5)

A few notes about these variables:

  • C1 and C2 presume a royal flush is possible i.e. the community cards have the 4 or 3 necessary cards and just give the odds of a player having the remaining 1 or 2 cards. That’s why 47 shows up in those equations, because 5 of the 52 cards in the deck are already accounted for as the community cards.
  • C1 has 2 as a factor in the numerator because a player has 2 chances of getting the remaining 1 necessary card. In C2, the player must have both cards necessary, so there is no extra factor.
  • In RFX 4 is a factor because there are 4 possible royal flushes.

Plugging in the numbers for X = 10 we get:

  • C1*C4 = (2*10*(5 choose 4)*(47 choose 1))/((47 choose 1)*(52 choose 5)) = (20*(5 choose 4))/(52 choose 5) = 100/2,598,560 = 0.0000385
  • C2*C3 = (10*(5 choose 3)*(47 choose 2))/((47 choose 2)*(52 choose 5)) = 10*10/2,598,560 = 0.0000385
  • C5 = 1/2,598,560 = 0.000000385
  • RFX = 4*(0.0000385+0.0000385+0.000000385) = 0.00030954 = 1 in 3,233 hands

That’s exactly the same result via the first formula, phew. One non-obvious tidbit this way of thinking highlights is the probability of getting a royal flush with 4 cards in the community and one card in your hand (C1*C4) is exactly the same as getting a royal flush with 3 cards in the community and 2 cards in your hand (C2*C3).

Now that all the hard work is done, estimating how often one might expect two royals flushes at a ten player table where everyone stays in until the river on every had would be 0.00030954^2 or 0.00000000958 or 1 in every 10,436,778 hands. If I played 3,900 hands/year as originally estimated, I could expect this event to happen once every 2,676 years. Using our more realistic earlier estimate that one out of every three hands sees a river card and when that happens, there are three players still in the game, a royal flush would happen 1 in 34,200 hands (0.00002924) and a back-to-back occurrence would be 0.000000000855 or 1 in every 1,169,590,643 hands. For some perspective, the odds of winning the MEGA Millions Lottery jackpot are almost 7 times better, approximately 1 in 176,000,000!

February 27th, 2012

The World of Tumblr

My Flickr account, while public, is not something that gets many views. According to the stats, my photos have been viewed 23,710 times. 10% of those views are for one photo someone decided to link to in a comment on Digg in 2009 (original post is here and someone re-posted a link to my photo as a story here Three Rupicaprid Ninjas Climb A Steep Cliff Wall).

Mountain Goats From Goat Lick Overlook

Digg did not allow embedding images directly into the post so I got to see the explosion of views firsthand. Recently I noticed a couple of referrers from tumblr.com in my stats, and they all happend to be for the same image of Yogurt Drinks from Amsterdam.

Yogurt Drinks

The Flickr stats showed only a few tens of people looked at the image directly on Flickr, but I was still curious what people were posting about my image. It turns out, there wasn’t much. The image was just one in a stream on various image centric tumblelogs. However, there were 775 “notes”, most of which appeared to be in a particular format: TumblrUser this

For example:
fairyfloss89 reblogged this from fusels
jessicajmaciel liked this
jessicajmaciel reblogged this from urban-princess

The UNIX utilities cut, sort, uniq and grep are my friends, so it was relatively easy to get some stats out of this data:

cut -d\ -f2 notes | sort | uniq -c

 156 liked
   1 love
   1 nomk
   1 posted
 606 reblogged
   1 reeeaally
   2 want

That command says using as a delimiter (-d\ ) print the 2nd field (-f2) of each line, sort them and then count (-c) the number of unique occurances. Looks like there were 156 likes and 606 reblogs, so what where the others?

grep -v “liked\|reblogged” notes

i want a smoothie:(
id love to scoop one of these up
omk nomk nomk :D
I reeeaally want a mango pineapple smoothie right now.
DRINKING ONE RIGHT NOW
I want them all.
candystaples posted this

That command says print all lines that don’t contain (-v) the words liked or (\|) reblogged. Looks like 6 people decided to post a comment and the source post came from candystaples (here’s a link to the actual post). People can both like and reblog the image, how many of those were there?

cut -d\ -f1 notes | sort | uniq -c | grep “^ \+2″ | wc -l

38

That command says using as the delimiter (-d\ ) print the 1st field (-f1) of each line, sort them, count (-c) the number of unique occurrences, print the lines that begin (^) with 1 or more characters followed by a 2, and count those lines (-l).

So at least 606 + 156 – 38 = 724 unique people saw my image and liked or reblogged it. It turns out, when reblogging the comment format is TumblrUserA reblogged this from TumblrUserB. So candystaples was the source, but which other tumblelogs generated the more reblogs?

grep “reblogged this from” notes | cut -d\ -f5 | sort | uniq -c | sort -r | head”

  86 fusels
  75 iamfuckingglamorous
  37 dingyfeathers
  31 fashionistha
  17 madamelulu
  16 s-o-u-l
  14 urban-princess
  11 breakingthehabits
  10 izzyparadise
   9 sellyourseconds

That command says print all the lines that contain “reblogged this from”, using as a delimiter (-d\ ) print the 5th field (-f5) of each line, sort them, count (-c) the number of unique occurances, sort those in reverse/descending (-r) order and print the first 10 (default for the head command).

I hadn’t really thought about what sort of multiplier to attach to my Flickr stats in order to determine how many people had actually viewed one of my photos. Clearly not every photo deserves a 10x or greater multiplier and in cases like this, 10x is likely to small e.g. if 700 people took the time to perform a like or reblog action, is that 1% of the number of people who actually saw the image? And this doesn’t take into account the times photos are just copied and posted elsewhere with no attribution e.g. my experience with a Famous Board Games Photo.

February 7th, 2012

City of Sacramento Parking Ticket Nonsense

When was the last time you put a coin into a parking meter and had to turn a knob in order to complete the transaction? I can’t remember when I last watched the red or yellow metal plates rise and fall, checked to see if the arrow indicated I had been credited the appropriate amount of time.

parking meterGrowing up, I got a kick out of turning the knobs as I walked by, so tactile, usually accompanied by a grinding noise and then a clang as the arrow and plates sprung back into place. Nowadays when paying for street parking, more often than not I have to walk to a centrally located kiosk, get a printed stick and place it in a particular spot inside my car, but the notion of a parking meter still conjures up images of the mechanical one from my childhood. Note: The parking meters I remember apparently are made by a company named Duncan e.g. Duncan Parking Meters


My dad and grandmother flew in from the East Coast this past Thanksgiving and we all went up to Sacramento to spend it with my wife’s family. After Thanksgiving dinner we drove to a hotel and I found parking across the street from the hotel. There was a sign (shown below as viewed from the driver’s seat the next morning) stating it was 1 hour parking from 8a-6p. I knew we’d be leaving before 9a the next morning, nothing indicated there was a fee and there was no parking meter by the car. It was late and dark so we hustled into the hotel to check-in.

parking

The next morning we were at the car by 8:45a and to my surprise there was a parking ticket on the windshield. I looked around and saw a pay for parking kiosk about 75ft behind the car which I had missed the previous night as I had not looked in that direction. I vowed to contest it when I got home and wrote this:

December 4, 2011

City of Sacramento, Revenue Services
P.O. Box 2551
Sacramento CA 95812-2551

Dear Sir/Madam,

I would like to contest this parking citation:

Citation #: #########
Issue Date: 25-Nov-11
Location: 1215 J St
Violation Code: 10.20.090 Meter Expired
Vehicle License #: #######

I parked at the above location around 10pm on 24-Nov-11 and saw the sign that said 1hr parking 8am-6pm. The next morning at 8:45am I went to move my car and saw I had been issued a parking ticket. There was no meter on the sidewalk next to the spot and no sign indicating the spot was metered. Here is a photo I took that morning from my car of the parking sign as viewed from the driver’s seat. I appreciate your time and understanding.

Sincerely,

James Pine

Because this was a legal challenge, I sent the letter via certified mail and requested a return receipt. My total postage cost was $5.74 or 13% of the actual fine! After nearly 3 months, I received the judgement and of course they denied my request to waive the fee, citing rule #2 of the 13 Ways to Park Legally in Sacramento. Looking 100ft in either direction due to these parking pay stations seems like a step backward from the time when a meter right next to your car contained all the information necessary. To be fair, accepting credit cards and paper money in addition to coins is a step forward…though the number of times a parking machine has failed to accept my credit card or paper money is non-zero. Anyway, the real problem was that I did look for a parking sign, saw one above my car as indicated in the photo and did not consider that I might have to hunt down another parking sign for corroboration.

I would have continued contesting the ticket except for the fact that we donated our car to a charity a few weeks ago and didn’t want to cause them any trouble during their attempt to sell it. Perhaps the City of Sacramento will use the revenue from my citation to put up the proper signage…