# ROYAL FLUSH

I once got dealt a royal flush.

That’s right. A “natural” royal flush. On a quarter video poker machine.

To make matters even more amazing, it was on the first quarter I gambled that day. (Can you imagine if the guy who had been playing that machine for hours just before saw me come over to “his” machine and hit a royal flush on one quarter?)

The probability of being dealt a royal flush is quite low. There are exactly four such hands — one for each of hearts, spades, clubs and diamonds — and there are 52!/(47! * 5!) different poker hands.

[Where does this number come from? Well, the first card has to be one of the 52 cards in the deck. The second has to be one of the 51 remaining, so there are 52*51 ways to get two cards. The third has to be on of the 50 remaining, so there are 52*51*50 ways to get three cards. Using this reasoning, there are 52*51*50*49*48 ways to get dealt five cards. But rearranging the cards doesn’t change what’s in the poker hand — that is, ace of clubs and two of hearts is the same as the two of hearts and the ace of clubs — so we have to divide by the 5*4*3*2*1 ways to arrange the cards.]

So there are 2,598,960 different poker hands, and exactly four of them are royal flushes. This means the odds of being dealt a royal flush are 1 in 649740.

Them’s not very good odds.

Here’s what happened. Several years ago, I was flying somewhere — I believe to Spokane to visit a friend of mine that lives just over the Idaho border in British Columbia. My plane landed in Las Vegas. I had to switch planes, so I got out and went to the gate. I had a good 45 minutes before boarding started, so I thought I would do some gaming. After all, how much can you lose in 45 minutes?!

I selected a quarter video poker machine. I put in my money and hit deal. It dealt out the cards pretty fast, then made the little happy note sound and highlighted the “Royal Flush” payout line. I was a little surprised (to say the least) and not too sure what was going on. It took me a few seconds to realize that I had actually been dealt a royal flush. I held every card (I was once dealt four deuces in a “Deuces wild” game and I was so flustered, I failed to “Keep” any of them, and thus failed to collect my \$50), and hit “Draw”. Ta-da! For my one quarter, I won \$75.

If I had put in five quarters, I would have won \$1000. Yikes!! So of course I immediately started kicking myself for not having put in five quarters. But hey, what can you do.

Yeah, it was cool. But it was also a downer. I had hoped to kill 20 minutes or so. Now what was I supposed to do… keep playing? As a percentage, I was WAY up. And extremely unlikely to change that one way or the other.

I played a few more anticlimactic hands of poker, then cashed out my now \$60-some odd dollar draw and went on my way.

It’s great that I got it. But also it’s a bit of a downer — not because I never CAN do it again, but because I probably never WILL do it again. If you play 450365 hands, you have a 50-50 chance of seeing a royal flush. I probably won’t play anywhere near that number, so I have much less than a 50% chance.

Of course, that’s just being DEALT a royal flush. The odds that it will happen with a draw are much higher, but it’s harder to calculate because it depends upon your strategy. Nevertheless, since I don’t play poker that much, I think it reasonably prudent that I don’t expect to see a royal flush ever again.

But that’s okay. I got mine.

# Lazy Bones

I’ve always been proud about how lazy I am. I often say that I will do an incredible amount of work just so I can be lazy. Something along those lines happened today, and I realize that what it is is that I hate is routine busywork; so much so that I would rather do a certain quantity of creative work to avoid an equal quantity of busywork.

At my company, we have used Apple’s deprecated WebObjects 4.5, which uses Objective-C and WebScript. Years ago, WO4.5 was the most fun web development environment, but since it turned 5.0 and substituted Java for Objective-C, it’s been much less fun and it’s not used very widely outside Apple, and it’s not really admired as much as it used to be. It’s gotten worse (Java over WebScript? Get real) and other environments have gotten better (I like Django a lot right now).

Anyway, we have a specific application that has been bothering us for a long time, and it’s time to port it.

I’ve been looking at “SQLAlchemy”, a Python-based object-relational modeling tool that works with Oracle (which I hate, but that’s a story for another time). It seems using this tool will make the port from WO4.5 to Python a fair bit easier.

The first step seemed to be to create new model files that describe the object-relational mapping. Of course, the syntax for these files (pure Python, it turns out) is quite different from the syntax used in WO’s EOF object-relational mapping layer. We have a lot of objects, so rather than do it by hand, I thought I would write a tool to do it.

EOF uses a plist file format. There are Objective-C routines to read these files, but I couldn’t find any libraries to do so in Python. So I installed pyobjc so I could use one particular Objective-C call from Python. This made parsing very easy, and creating the Python model file was a piece of cake.

It’s not 100% yet, but I was quite amazed not only how quickly I could produce the translation tool, but what great lengths I would go to to be lazy.

# Revisiting my Cubist Period

In preparation for a Rubik’s Cube contest at an 80s party I went to last week, I picked up the puzzle and have been studying and playing around with it a bit lately.

I happened to be in Hungary in the summer of 1980, shortly after the cube was invented by ErnÃ¶ Rubik, and several months before it became popular in North America. Someone gave me an article in Hungarian about how to solve it. I can’t read Hungarian, but it included a bunch of photos and some “patterns” — that is, series of moves that tweak a small number of “cubies” without disturbing anything else. With these patterns and a little initiative, I taught myself to solve it.

With practice, I could solve it pretty reliable in 90-120 seconds. That’s where I am now. My algorithm is quite simple: first, solve one side. This step does not use any patterns besides one that I devised myself. Each of the following steps does use patterns: place the corners, orient the corners, place the edges, orient the edges.

Three of the four patterns were extracted from that mysterious magazine article, but the forth, which orients the edges, I replaced with a pattern a friend of mine showed me. He called it “Rubik’s maneuver”, so who knows, maybe it was discovered by Rubik himself.

Although 90 seconds is okay, it’s definitely not world class. The real pros can solve it in less than 30 seconds consistently. Maybe less than 20. I’ve look at this site which has a different method of solving the cube that does not do one side first. There are some interesting ideas here I’m going to explore further.

(Oh, by the way, the contest was canceled… they forgot to bring the cubes.)