I love to travel. And something that makes that a lot easier is cheap flights. There are many websites and even twitter accounts that exist only to point out cheap flights. For about a year I’ve followed several twitter accounts for fare deals and have alerts turned on so that I don’t miss something good. Currently, I get about 50 alerts a day that light up my phone and distract me from whatever I’m doing… but only one or two of those are actually from my home airport of DEN. So I created a python script to help me out.
Nate Silver (of 538 fame) tweeted an interesting problem today. Somebody on Reddit had averaged the birthdays of all the presidents and found it to be July 4th (link). Nate responded that it was wrong and said the real average is sometime in late November. I thought it was an interesting problem and figured I’d work on my python skills so I decided to see for myself and threw in a couple of alterations as well.
Have you heard of Fizz Buzz? It’s commonly used as an basic software interview question or an intro programming example. It’s based on a game meant to teach children division and goes like this. The children sit in a circle and count up from one; but, if your number is divisible by 3 you say “Fizz” instead of your number and if your number is divisible by 5 you say “Buzz” instead of your number. If your number is divisible by both 3 and 5 you say “Fizz Buzz”.
Many of you are familiar with the Birthday Paradox. If you want to read more about it you can find a good article here. Basically, it says that in a room of 23 people, there is a 50% chance that at least two people share a birthday. And if you increase that number to 75 people, the chances go up to 99.9%. I wanted to explore this a little more and rather than doing the math (boring!), I decided to do a Monte Carlo simulation, run it a bunch of times, and plot the results.
I’m working to bone up on my python skills so I decided to spend my Sunday doing problems 1-10 from Project Euler. I’ve done them before with C or Java but this was my first time with Python. Here are the problems and my commented code for each one in case it interests anybody.
Last week a podcast I listen to, the 404, discussed a math problem where you roll six 20-sided die and count how often you get a situation where at least one dice matches another dice. They discussed the math a little and came to the conclusion that it happens far more than you’d think. I thought it’d make a good monte carlo programming exercise so I’ve done just that. Below, you’ll find my C code (though it’s not great) and results for 2-20 dice.
Here’s my solution to this week’s Riddler Express question from FiveThirtyEight. Here’s the question: “You place 100 coins heads up in a row and number them by position, with the coin all the way on the left No. 1 and the one on the rightmost edge No. 100. Next, for every number N, from 1 to 100, you flip over every coin whose position is a multiple of N. For example, first you’ll flip over all the coins, because every number is a multiple of 1. Then you’ll flip over all the even-numbered coins, because they’re multiples of 2. Then you’ll flip coins No. 3, 6, 9, 12 … And so on. What do the coins look like when you’re done? Specifically, which coins are heads down?”