Great Big House in New Orleans: Improved Code

On Monday, I wrote a post about how I wrote a program in Java and later Python that could solve an old game I used to play in my elementary school music class called Great Big House in New Orleans. It was a lengthy post, and you can read the entire thing here. Basically, in the game, all students in the class sat in a circle and passed a stuffed pumpkin around while singing a song. The rules of the game were such that every eighth student gets out (i.e. exits the circle), and the last student to remain in the circle wins.

The program that I initially wrote in Java used arrays to simulate an actual game of Great Big House in New Orleans. However, using data of winning positions based on class sizes up to 1000, I was able to identify a pattern in consecutive winning positions that I could use to simplify my program so that it could solve for the winning position without having to simulate a single game with arrays or lists.

The code is structured as follows.
  • You are given (by the user) an arbitrary class size class_size.
    • Let the variable winning_pos be set initially to 2.
    • Let the variable temp_class_size be set initially to 2.
    • If the class_size inputted by the user is 2, then:
      • Set winning_pos to 2. (I realize this is an unnecessary step because winning_pos is already initialized to 2, but I think it's helpful for readability of the code. The starting point (2, 2) is the smallest possible Great Big House in New Orleans game, and it is the only game you need to accept as a given in order to solve all other games, as demonstrated this code.)
    • Otherwise:
      • While our local variable temp_class_size is not equal to the user-inputted parameter class_size:
        • If winning_pos is equal to 1, then:
          • Add 7 to winning_pos.
          • Remember, this is our special case where our (c0, w0) pair is (c0, 1), so we need to do a single "7-run" rather than an 8-run.
        • Otherwise:
          • Add 8 to winning_pos.
        • If winning_pos is greater than temp_class_size, then:
          • Keep subtracting temp_class_size from winning_pos until they are less than or equal to each other.
        • Keep repeating the above steps until temp_class_size becomes equal to class_size.
    • The final value of winning_pos is your winning position for the class size class_size.
In Python, it looks like this:


Turns out, this is all the code you need in order to solve Great Big House in New Orleans. Here's the full code on GitHub. Since it is far simpler than the array method, it leads to decreased processing times for large class sizes. In my original post on Monday, I ended with the challenge of finding in which position you need to sit in order if all 7.6 billion human beings on planet Earth got together and played a game of Great Big House in New Orleans. Unfortunately, the simulation/array method of the program took too long to calculate the winning position to feasibly attempt solving 7.6 billion, but this new and improved code could do it in a few minutes without any problems.

At first, we underestimated the current population of Earth, so we inputted a value of 7.4 billion instead of 7.6 billion. It took a few minutes; however, the program finally outputted that position 4,721,182,147 would win when 7.4 billion people were playing Great Big House in New Orleans.


Instead of waiting several minutes longer for the program to do 7.6 billion, I used the result from 7.4 billion to create a formula that would allow me to find the result at 7.6 billion. The formula is simply the linear point-slope form:
w = 8(c - 7.4 × 109) + 4721182147
The x-intercept of this line (i.e. the "c-intercept"; the value of c when w = 0) is approximately 6.810 × 109, and the point at which this line intersects the line w = c occurs approximately when c = 7.783 × 109. As a result, this formula is valid for class sizes between approximately these two bounds. 7.6 × 109 is well in between these two values, so we can simply substitute it for c in the equation to find the winning position for a class of size 7.6 billion.

If exactly 7.6 billion human beings got together and played a game of Great Big House in New Orleans, you would need to sit in position 6,321,182,147 in order to win.


Update 12/17/2017: I ran the program for a class size of 7.6 billion. Lo and behold, position 6,321,182,147 wins.