Riddler Classic

By Zach Wissner-Gross

From Ricky Jacobson comes a party game that’s just in time for Halloween:

Instead of playing hot potato, you and 60 of your closest friends decide to play a socially distanced game of hot pumpkin.

Before the game starts, you all sit in a circle and agree on a positive integer N. Once the number has been chosen, you (the leader of the group) start the game by counting “1” and passing the pumpkin to the person sitting directly to your left. She then declares “2” and passes the pumpkin one space to her left. This continues with each player saying the next number in the sequence, wrapping around the circle as many times as necessary, until the group has collectively counted up to N. At that point, the player who counted “N” is eliminated, and the player directly to his or her left starts the next round, again proceeding to the same value of N. The game continues until just one player remains, who is declared the victor.

In the game’s first round, the player 18 spaces to your left is the first to be eliminated. Ricky, the next player in the sequence, begins the next round. The second round sees the elimination of the player 31 spaces to Ricky’s left. Zach begins the third round, only to find himself eliminated in a cruel twist of fate. (Woe is Zach.)

What was the smallest value of N the group could have used for this game?

Extra credit: Suppose the players were numbered from 1 to 61, with you as Player No. 1, the player to your left as Player No. 2 and so on. Which player won the game?

Extra extra credit: What’s the smallest N that would have made you the winner?


My Solution

We’ll start off as always by brute forcing our way to the answer. I’m sure that the actual solution is some elegant epiphany of least common multiples or whatever, but I don’t have time to sit around and wait for an epiphany.

hotPumpkin <- function (N, players = 61) {

  pumpkinIndex <- 1
  playersLeft <- 1:players
  playersElim <- c()
  
  while (length(playersLeft) != 1) {
    # index of playersLeft where pumpkin will end up
    pumpkinIndex <- (pumpkinIndex + N) %% length(playersLeft)
    if (pumpkinIndex == 0) {
      pumpkinIndex <- length(playersLeft)
    }
    
    # eliminate player with pumpkin
    playersElim <- append(playersElim, playersLeft[pumpkinIndex])
    playersLeft <- playersLeft[-pumpkinIndex]
    
    # the pumpkin should be in the right place after a player is eliminated
    if (pumpkinIndex > length(playersLeft)) {
      pumpkinIndex <- 1
    }
  }
  
  return(playersElim)
}

Troubleshooting that function was kind of a nightmare. The person 18 spaces to my left is number 19 in the sequence and is the first to get eliminated. Ricky is number 20. Number 51 gets eliminated next and Zach, number 52, is the next to be eliminated.

N <- 1
answerFound <- F
while (!answerFound) {
  if (!(FALSE %in% (c(19,51,52) == hotPumpkin(N)[1:3]))) {
    print(paste("The first three players eliminated are numbered 19, 51, and 52 when N =", N))
    answerFound <- T
  }
  N <- N + 1
}
## [1] "The first three players eliminated are numbered 19, 51, and 52 when N = 136231"

I guess that the answer’s 136,231? That’s going to be an absurdly long game of Hot Pumpkin… I won’t lie, though — I thought that my code was broken because I only searched up to N = 10,000 and N = 100,000 at first. Using the same code the extra credits will be pretty simple.

print(paste("The winner of that game of Hot Pumpkin was player number", match(FALSE, (1:61 %in% hotPumpkin(136231)))))
## [1] "The winner of that game of Hot Pumpkin was player number 58"
N <- 1
answerFound <- F
while (!answerFound) {
  if (!(1 %in% hotPumpkin(N))) {
    print(paste("Player 1 will win when N =", N))
    answerFound <- T
  }
  N <- N + 1
}
## [1] "Player 1 will win when N = 139"