Digging into the Monte Carlo Algorithm

After hearing about the Monte Carlo Algorithm over beers with friends one night, I decided to get a better understanding of how it works and learn a bit more about poker along the way. For me, there is no better way to understand a problem than coding up  and launching a product around it.

Have you ever watched a Texas Hold ’em Poker Champion on T.V.? Every time a set of cards are laid out on the table the odds of each player’s hands is provided to the audience (for example, Lindh has a 75% chance of winning with his K and 9 of clubs above). Advanced poker players have become quite good at predicting the odds as a gut instinct and is partly why mathematicians enjoy the game so much.

In order to practice my ability to develop a second-sense for poker odds, I figured repetition was the key. The game I set out to create would lay out a set of cards and allow the user to predict the percentage probability of converting that to a winning hand, quickly, over and over again.

Of couse, there are far fewer total combinations of game-plays for a poker game as compared to a game of chess; so it isn’t rocket science. However, the variation in the number of players combined with a 52 card deck does create enough variation to make things interesting.

In order to make the solution robust, I used a Monte Carlo algorithm to generate thousands of possible outcomes randomly and recorded the statistical output for “player 1” to win.  Once the algorithm was completed in Python, I built a Google Polymer app to present the probability guessing game.

You can test your ability to guess your probability of winning a text hold ’em hand in the  game here.

Touch Sensitive Button Using Conductive Fabric and Velostat

For this experiment I decided to dive deeper into the EE side of things and wanted to get a feel (pun sort of not intended) for how it all worked. My goal was to figure out how to create a pressure sensitive button made out of fabrics, and hook it into an Arduino so I could program around the haptic feedback.

I thought it would be easy to find the parts and videos I needed to get to my goal, but was surprised to find few videos that took the viewer from start to finish. So, I decided to record what I learned along the way so that others may have it easier.

First, let’s start with the materials:

  1. Velostat
  2. Conductive Fabric
  3. 2x Alligators Clips
  4. Multimeter

In short, Velostat is a resistive material and feels like it is cut out of a trash bag. The conductive fabric is a fabric that has conductive material woven into each strand. If you hook up each piece of fabric to a battery and touch those pieces of fabric together you will create a complete circuit. (Be careful, this can cause a fire when the wires spark around the fabric.)

When you place the Velostat between those two pieces of fabric you make it harder for the electricity to flow from one piece of fabric to the next (ergot “resistor”). Since the Velostat is thin and malleable, pressure from your finger onto the sandwiched materials increases or decreases the flow of electricity. This change in electricity is the signal you will interpret in your “pressure gauge”.

This video shows you how you put it all together. If you remember the principles above the rest becomes fairly easy. For example, you must be sure that none of your conductive fabric touches one another, so make sure your Velostat swatch is larger than you fabric swatches.

Now that I got that working I set out to connect the system to an Arduino so I could read the change in resistance on the computer.

Materials:

  1. Same materials in Part 1 (Multimeter not required)
  2. 1N4003 Diode
  3. Arduino UNO
  4. Jumper Cables
  5. Arduino SDK
  6. Computer
  7. USB/Serial Port Connector
touch_sensor
#include <math.h>
int myPin = 0;
int touching = false;
int touchingCount = 0;
void setup() {
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
int sensorValue = analogRead(myPin);
String amount = "Start Touch";
if (sensorValue > 90) {
touching = true;
touchingCount++;
} else {
touching = false;
touchingCount = 0;
}
if (touching && touchingCount < 20) {
amount = "Tap";
} else if (touching) {
amount = "Hold";
}
if (sensorValue < 90) {
// Serial.println("Not touched");
} else if (sensorValue < 120) {
Serial.println("Light " + amount);
} else if (sensorValue < 160) {
Serial.println("Strong " + amount);
} else if (sensorValue < 190) {
Serial.println("Hard " + amount);
}
}
view raw Advanced Reads hosted with ❤ by GitHub
#include <math.h>
int myPin = 0;
void setup() {
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
int sensorValue = analogRead(myPin);
Serial.println(sensorValue);
}
view raw Basic hosted with ❤ by GitHub

The Best of Reykjavik Dinning

Did you know Iceland was under prohibition until 1989? Maybe all that time sober is what allowed the chefs in Iceland to master their craft. At first we thought we got lucky when our first meal was insanely good, but every place we went, from cafe’s to grills, put a smile on our bellies.

Our first dinner was a 9-course tasting meal at Grill Market (Grillmarketdurrin). Maybe it was the modern ambiance, or seeing the sun shine past 11PM, or the wonderful aromas we caught from sitting next to the kitchen, but whatever it was, it was one of the best meals we’ve ever had. (Checkout what we ate in the video below).

We were warned that Iceland was “cheap to get to, but expensive to stay”. So we weren’t surprised that the meal above set us back $116USD per person. That being said, the price included all tax and tip, and the quality, freshness, and size of our dishes were top notch. Factoring in the $1USD to $101ISK conversion, and the “all in” price tag, the menu price for that meal in San Francisco would have been $89. Not cheap, but an amazing deal for what we got.

Not every meal could be rationalized as “worth it”. While touring the Golden Circle we grabbed some food at a gas station quicky-mart. Our two small sandwiches and two small coffees came out to about $24USD, and a gallon of gas was about $7.50USD. So yes, you will feel the pinch of the higher price tags on the everyday stuff. Nevertheless, when it comes to dinning-out, we still think you come out ahead from the overall experience. Which is likely why Iceland still sees tourists come in droves.

Take our next meal at Messin for example. The “Pan Fish” was fresh, delicious, prepared quickly, and was plentiful in portion. A combination that would be hard to come by in the U.S. where the “menu price” would be about $30.  Again, you pay a premium on crap food and gas, but you win big when you consider the quality of food you get when dinning out.

After a couple days in Iceland it was time to clean some clothes. Conveniently, we read about a cafe down the street from our apartment that offered a laundromat in the basement called The Laundromat Cafe. Since we had laundry, and we were hungry, we took advantage of the combo. We were glad we did! I had the smoked trout with cream cheese on rye. Yum! Even the Chai tea I ordered was one of the better ones I’ve had.

With our clothes freshly cleaned and our whistles in need of wetting, we hopped on over to The Lebowski Bar. Yes, a bar in Iceland is dedicated to the movie The Big Lebowski and offers up 21 different varieties of White Russians. Those that know me know that (A) I’m a fan of the movie and (B) my drink of choice these last few months have been White Russians.

I wouldn’t go as far as to say these were the best drinks in the world, but they were good and it was fun to try a few versions of the after-dinner cocktail (about $20-$30 a pop).  The scene was fun and carried a big crowd, all enjoying the 80s music that you could hear from across the street.

The next morning we hopped over to the Bonus grocery store and got a pint of Skyr, Iceland’s traditional breakfast food. It’s basically a very thick yogurt, and goes great with berries. Although tasty, I wouldn’t say it is as unique as it is made out to be. Imagine a thick greek yogurt with a slightly more sour taste.

For our final restaurant we wanted to taste some Icelandic home cooked, traditional, comfort food. For that we found Salka & Valka (Fish and More). There we ordered the fish soup and traditional fish stew made with mashed potatoes, white fish and green onions. The dish was soft, creamy, and very comforting;  just what we were looking for!

We were on such a roll with food, that when the sign on the table said “You must try our rhubarb pie” we couldn’t resist. Sadly, the dry, underwhelming dessert was the only fail of the week. Don’t worry Iceland, we still love you!