musings, puzzles & programming

Supreme Gridlock

Last week I won the FiveThityEight Riddler! (don’t get too excited, the winner is randomly selected 😉)


I don’t share every riddler I work on, but this one is straightforward yet interesting, politically applicable, and was fun to work on.

Here is the riddle:

Imagine that U.S. Supreme Court nominees are only confirmed if the same party holds the presidency and the Senate. What is the expected number of vacancies on the bench in the long run?
You can assume the following:

  • You start with an empty, nine-person bench.
  • There are two parties, and each has a 50 percent chance of winning the presidency and a 50 percent chance of winning the Senate in each election.
  • The outcomes of Senate elections and presidential elections are independent.
  • The length of time for which a justice serves is uniformly distributed between zero and 40 years.

Additional clarifications I made:

  • President elected every 4 years, Senate every 2 years.
  • Judicial terms will be integers (whole years), and if a judge leaves on an election year, the seat will be potentially filled by the incoming government.

I have omitted some of the code for brevity. Full code here

Read More

Dollars to Doughnuts

Today’s post is a (relatively) quick one to do some visualization on my financial data. Specifically, I was interested in whether some concious changes I had made in my dietary habits have materialized into measurable savings.

To date, I haven’t really focused too much on reducing my food spending. I keep a budget for it, but pretty regularly exceed it. However, in February I took a close look at how much I was actually spending and tried to take some steps to reduce my spending. The main areas that I looked to cut were eating take-out and getting breakfast & lunch at work every day. I’ve been making some concious efforts in those areas over the past ~4 weeks or so, including cooking large batch meals to bring for lunches at work.

In the post I’m going to run through the analysis I did to determine whether my changes had a financial impact.

Read More

Podcast Roundup: March 2017

Hello again everyone! This time, I’ll take a break from programming and tell you about another of my favorite things: podcasts. Podcasts are audio-only programs, spanning all types of genres. They are typically released on a regular schedule and free (mostly ad supported) and there’s something out there for everyone! If you want to read more about them, wikipedia has your back, as always: podcast. If you’re new and unsure how to listen, check out this helpful guide!

In this post I’m going to share three of my favorite shows, hopefully some that you don’t listen to already. For those who are familiar with podcasts, I’ve tried to stay away from some of the very popular shows like This American Life, Radiolab or Serial. If you have never listened to podcasts before, both of those shows are definitely worth checking out as well. Without further ado…

Read More

Finding Boggle Grid Scores

If you haven’t read my last post, go ahead and read that before diving in here. It’s not strictly necessary, but it will give you some context.

In my last post discussing high scoring Boggle boards, I skipped over some important details. Because I wanted to keep my focus on the genetics aspect of the solution, I didn’t walk through actually scoring the boards. A few people have asked me about the details, so I thought it’d be fun to share that as well. If your recreational reading is solely focused on Boggle board solving, there are

Read More

Generating Boggle Boards with Genetics

Each week, FiveThirtyEight posts a puzzle call the Riddler. On Oct. 21st, this was the Riddler:

What arrangement of any letters on a Boggle board has the most points attainable? Boggle is played with a 4-by-4 grid of letters. Points are scored by finding strings of letters — connected in any direction, horizontally, vertically or diagonally — that form valid words at least three letters long. Words 3, 4, 5, 6, 7 or 8 or more letters long score 1, 1, 2, 3, 5 and 11 points, respectively.

I had a lot of fun solving this puzzle, and I learned a lot as well, so I decided to share. The approach I took was to use a genetic algorithm, which mimics the mechanics of natural selection. In the past, I hadn’t found a good application, but wanted to give it a shot. You shouldn’t need in-depth knowledge of programming, genetics, or Boggle to learn something!

Read More