Category Archives: Random

Brute forcing the roulette wheel

There comes a time in every programmer’s life where they want to write a simulation to see how much they’d lose at the tables. Here’s mine. It’s a test of the Martingale Betting Strategy using a simulated roulette wheel.

The Martingale Betting Strategy is based on the idea that with payouts of 1 to 1, there is a good chance that you can recover lost bets when you achieve a win. The strategy has been used in roulette, where the probability of winning on red and black is close to 50%.

In general, the strategy is to double a bet whenever you lose in the hopes that the color you lost on will eventually come back around and you’ll recover your loss. For example, if you bet $1 on black and lose, you would then place $2 on black the next time. If black wins on the next spin, you recover your lost $1 and gain $1. If black loses again, you double the $2 and make a $4 bet. If you win this time, you’ve recovered the $1 + $2 you’ve spent and collect a $1 gain. If you lose again, you double the bet to $8. And so on. Again, the idea being that black will eventually come around and, so long as you keep doubling the bet, you’ll eventually recover your losses while earning a $1 gain whenever you don’t lose. There are 38 slots on an American roulette wheel: 18 black, 18 red, and 2 green. The probability of hitting a black or red on any single spin is 47.37%.

The bane of this system is the inevitable streaks of a particular color. Doubled bets increase exponentially. A $1 bet doubled 10 times becomes a whopping $1024 ($2, $4, $8, $16, $32, $64, $128, $256, $512, $1024)! In theory, if you have an infinite bank roll, you would always recover your losses because black always does come back round eventually. In practice, the upper limit is the table’s max bet and the money you bring to the table. You may not have a chance to recover your losses before exceeding the table limit on doubled bets.

Probability tells us that eventually we’ll either lose our bank roll or hit the table max bet. This simulation was written to visually represent how long one might go before hitting that wall.

For this simulation we will run up to 100,000 spins on a roulette wheel with bets using a modified version of the classic Martingale Strategy.

This simulation assumes the conditions of the standard video roulette machines I played in Vegas casinos. $3 minimum bet. $1000 maximum bet. I’m going to give it a bank roll of $1000 just to be generous. The max number of spins will be 100,000 (provided we don’t bust or exceed the table limits before reaching it). To achieve the minimum bet, we’ll start with $1 on red and $2 on black and double the bet on a losing color, while placing $1 on the winning color. Betting $1 on the opposing color is the only deviation from the classic Martingale Strategy, which only calls for doubling losing bets. However, this is both necessary to achieve the minimum bet of $3 total and also what you ought to do anyway. You have a 47.37% chance of recovering your loss by winning a doubled bet. However, in the absense of that, you will necessarily gain $1 unless it lands on green (a 5.26% chance). I maintain this is an improvement on the classic Martingale.

Spoiler alert, the house usually wins.

Spin the wheel here:

http://jeremyparnell.com/simulations/martingale.aspx

Making a PVC bow

10295192_10102564532667833_3319940798828772362_o

Fun project: Making a bow from a PVC pipe.

Photos cc by Jeremy Parnell.

The math of mosh pits

A pair of metal head physicists at Cornell University who enjoy going to concerts and throwing themselves into mosh pits (I’ve done this a time or two back in the day — it’s fun) have taken an interest in the rules of motion behind the activity. “It was basically just this random mess of collisions, which is essentially how you want to think about the gas in the air that we breathe,” one said. So, they went to concerts and studied YouTube videos, and eventually created a mathematical model representing mosh pits, which they presented at a meeting of the American Physics Society, and this very cool simulator where you can change variables and see how the little moshers act.

Missing time

I went to set a reminder for the time change on Mar 10 and it wouldn’t let me set it for 2 AM. I tried a couple of times before suddenly realizing that there is no 2 AM. That freaks me out a little. There is no 2 AM! It just doesn’t exist.

Trackable Bambi

BambiWhenever I take a trip, I like to bring along a trackable. Found this one in a nearby geocache. Poor little guy’s only been 321 miles so far.

I’ll be dropping him off in San Francisco somewhere.

[Update: There’s a great little travel bug hotel at the California Historical Society. Check it out if you get the chance.]

How would humans respond to alien visitors?

In the Star Trek universe, the people of Earth first make contact with an alien civilization (Vulcans, in fact) on April 5, 2063, 51 years from today. Marc Kaufman, who is a science writer for the Washington Post and author of the book First Contact: Scientific Breakthroughs in the Hunt for life Beyond Earth, shares his thoughts on how humans might respond to meeting intelligent extraterrestrial life for the first time.

“On one level, I’d hope there would be a huge amount of wonder and awe and a recognition of the vastness of the Universe. But I also imagine there would be a lot of defensiveness, as well,” said Kaufman, referring to some, like Stephen Hawking, who say we shouldn’t send messages out into space — because if a more technically advanced civilization comes to Earth, the outcome for the less advanced (us) would likely be bad.

But Kaufman has hope that Earthlings would welcome a visit.

“Look at the continuing fascination of Roswell or UFOs,” he said. “Throughout history, humans have looked to the skies and thought that we’ve experienced something ‘out there’ – be it angels or gods or spaceships. There is, I believe, a deep human craving that we aren’t alone, and that would be a significant part of our response.”

Crowds, sourced

When you hear the statistic that there are now seven billion people on the planet, you naturally wonder where they may all live. Dencity is a map that visually shows world population using circles of various size and hue. China, India, and Pakistan have the greatest population density and show bright on this map. Some areas are simply black and reflect the more inhabitable areas of the world.