Register
Submit a solution
Status: ‌Cancelled client request

Challenge Overview

Hard

Let's make a change so that foods are added at a particular time instead of all at once.

You already have a list of primes or a way to calculate them from the previous problem.

Let's add a numbering to game turns. Initially we are at turn 0. When the snake makes a move, it counts as one turn.

When the game turn is a prime number, add a next food.

How are we adding the food?

For that, let's implement a simple Linear Congruential Generator pseudo-random number generator algorithm.
Precisely,
let's calculate the next random number by

randomNum = (3 * randomNum + 0) mod m

where m = n*n, when n represents the board size. The starting seed of the random number is 13. This means that the first random number is 13, and the next one is always calculated by the above formula.

When the game turn is prime, proceed as follows:

  • Iterate for each board position, starting at 0 in the top left corner
  • If the board position is the current random number, add a food there
  • When a food is added, calculate the next random number, and proceed forward through the board.

This means that multiple foods can be added in one turn, if the pseudo-random numbers are increasing.

Foods cannot be added to positions where the snake is.

Review style

Final Review

Community Review Board

Approval

User Sign-Off

ID: 30366044