# Riddler Revisited

I’m taking a second crack at FiveThirtyEight’s Riddler problem. I thought I solved the problem two weeks ago, but my answer wasn’t quite right.

Here is this week’s problem:

There’s an airplane with 100 seats, and there are 100 ticketed passengers each with an assigned seat. They line up to board in some random order. However, the first person to board is the worst person alive, and just sits in a random seat, without even looking at his boarding pass. Each subsequent passenger sits in his or her own assigned seat if it’s empty, but sits in a random open seat if the assigned seat is occupied. What is the probability that you, the hundredth passenger to board, finds your seat unoccupied

I’m not even going to try and figure out the math for this puzzle. My statistics skills aren’t nearly strong enough. But my coding skills are. This is an easy problem to solve with a Monte Carlo simulation.

Here’s my python solution.

And the output charted.

The last passenger has a 50% chance of getting their assigned seat.

The number of passengers who get their assigned seats is distributed around 95, with a 1% chance of everyone getting their assigned seat (in the event the first passenger randomly chooses his/her own seat).

Interestingly, it doesn’t matter how many seats are on the plane. If there are 10 or 200 seats, the last passenger still has a 50% chance of getting their assigned seat. The second last passenger has  67% chance, and the 3rd last passenger has a 75% chance.

It’s easy to derive the equation for the Xth last passenger from this, even though I can’t figure out the math to prove it. The Xth last passenger has a X/X+1 chance of getting their assigned seat. So the 5th last passenger, has a 5/6 = 83.3% chance of getting their seat.

# Developing Trex – Pulse Energy’s new Hubot

Every month or so at work we run a Big Idea Day where developers can work on fun projects of their choosing. For our last Big Idea Day, I paired up with one of our co-ops and integrated Hubot into our chat room. A lot of the chatter at work happens online in a chat room, it’s handy for keeping noise down in an open work environment and for keeping our remote employees engaged.

Hubot is an open-source chat bot developed by GitHub. It has some productive uses, but it’s mostly used for the inane – like pug bombing, quoting the Ferengi rules of acquisition, and littering the chat room with animated gifs. We named our Hubot Trex and in a few short weeks he’s become a fixture in our development chat room.

There’s lots to like about Hubot. It’s a free, open-source project. When I ran into a bug, it was easy to fix it myself and contribute the patch back to the community. Hubot also supports pluggable scripts. There are hundreds available online to choose from (everything from Breaking Bad quotes to hangman) or you can write your own.

I wrote a plugin to keep track of leaderboards. We play a lot of boardgames at work during lunch (King of Tokyo and Dominion usually) and Trex is now responsible for tracking the winners of every game.

On the productive side, the goal is to use Hubot to centralize some of the operational tasks we do – like deploying new versions of our software, spinning up new machines, and diagnosing problems. If tasks are done via Hubot, there’s a persistent log in the chat room that everyone can read and it’s interleaved with comments from the developers about why things are being done. It’s especially handy for our remote employees.

p.s. Pulse Energy is hiring. If you apply, mention this blog post for bonus points.

# Cleanweb Hackathon – Epic Energy III

On Saturday I participated in my first hackathon – the Vancouver Cleanweb Hackathon. It was a 12-hour coding marathon, or at least it was for our team from Pulse Energy. While most participants spent the first 2 hours brainstorming, pitching ideas, and recruiting team members, we locked ourselves in a board room and started coding with barely any breaks for eating or peeing. We weren’t necessarily serious or competitive. We just had an ambitious plan and only 12 hours to make it work, so there was no time for socializing.

Earlier in the week, we spent two lunches brainstorming about ideas and planning how we would build our favourite idea, a building manager sim game. We knew we were in over our heads, but we hoped the extra prep work would make up for our lack of game development experience.

Below you can see the evolution of our game as we slowly added functionality, content, and graphics. I’m impressed with how polished it looked after only 12 hours. A lot of the credit goes to our graphic designer, Tyler.

This slideshow requires JavaScript.

Our biggest challenges were making the game realistic (we used real data as much as possible), fitting in all the functionality we wanted (sadly, a lot of cool features got cut), and hardest of all, keeping it fun. At 6 pm, with 2 hours left, we stopped coding and did a play-through of our game and realized it was horribly boring. At that point, we stopped adding new features and prioritized fun. We added quirky comments from grumpy tenants, a scoring system, a tweet button, and animations to make it seem more like a game and less like a budgeting exercise.

I encourage everyone to check out and play Epic Energy III, and tweet your high score. The goal is to save as much energy as possible while keeping your tenants happy (which should be explained on an intro screen, but that feature got cut). So far, my best score is 20,308. If you’re interested in the code, you can see all the commits on GitHub. Don’t worry, even if you can read the code, it’s not obvious what the best strategy is to get a high score.

We’re still planning on making some improvements to the game in the coming weeks even though the Hackathon is over. It’s good marketing for Pulse Energy and fun to work on.
Continue reading Cleanweb Hackathon – Epic Energy III