Math - Remainders - Challenge

Original question player 4 starts

Previous post, player 1 starts

Next up, 512

1 Like

In the original the fourth player starts.

Previous number :
512 % 4 = 0

next number, 266

1 Like

Original question: Given game time of 63 seconds, find which player’s turn (out of 4) it currently is.

Answer:

63 / 4 = 15.75
Now we use the decimal portion multiplied by our divisor to find the true remainder value:
.75 * 4 = 3
3 is our fourth player (since our list of players is indexed at 0), so it is player 4’s turn currently.

Previous post: Same as above, but with 266 seconds of game time passed.
Answer:
266 / 4 = 66.5
Now we use the decimal portion multiplied by our divisor to find the true remainder value:
.5 * 4 = 2
2 is our third player (since our list of players is indexed at 0), so it is the 3rd player’s turn currently.

1 Like

Original question: 63 % 4 = 3 so fourth player(+ 1) starts the game.

No previous number, so I generated one. 830, so…
830 % 0 = 0, first player

Pure C#

			var rng = new Random();
			var players = 4;

			//if rng is divisible by 4, then first(0 -> zero) player will start the game
			var whoStarts = (rng.Next(0, 1000) % players) + 1;

			Console.WriteLine($"Player {whoStarts} starts the game");

Next number → 666

1 Like

First we had a number: 63. So let’s find wich player will go first.
63%4 = ?

First let’s do division: 63 / 4 = 15.75
Next let’s find remainder of this equation and do multiplication: 0.75 * 4 = 3
That give us: 63%4 = 3

So first will go player number 4.

From earlier post we have number 666.
666%4 = ?

The same as above, division: 666 / 4 = 166.5
And now multipication: 0,5 * 4 = 2
So we have: 666%4 = 2

With remainder 2, player number 3 will go first.

As for a code:

Next number is: 1789.

1 Like

Player 3

1 Like

In your example, you state that we are not interested in the 2 from 2.8, but you never explain why. Why?

This is a remainder challenge. We are only interested in the remainder and hence we want to investigate the 0.8 of the 2.8 and we are not interested in the 2.

Does this help?

Kind regards, Lisa

1 Like

For 63:

63 % 4 = 15.75
Take the 15 away, and you’re left with 0.75
4 * 0.75 = 3, meaning Player 4 goes first.

In C++:

int main()
{
int goFirst{};
goFirst = 63 % 4;
if (goFirst == 0) {std::cout << “Player 1 goes first \n”;}
else if (goFirst == 1) {std::cout << “Player 2 goes first \n”;}
else if (goFirst == 2) {std::cout << “Player 3 goes first \n”;}
else {std::cout << “Player 4 goes first \n”;}
}

For the previous poster’s number: 1789

1789 / 4 = 447.25
4 * 0.25 = 1
Player 2 goes first.

Next number = 99

2 Likes

Thank you. :slight_smile:

1 Like

Python code below:

import random

#random_number = random.randint(1, 100)

random_number = 99
next_number = random.randint(1, 1000)

number_of_players = int(input("How many players are there?"))

print(
    f"\nRandom number is {random_number}\nNumber of players is {number_of_players}\n"
)

p1 = "Player 1"
p2 = "Player 2"
p3 = "Player 3"
p4 = "Player 4"

goes_first = str

if random_number % number_of_players == 0:
    goes_first = p1
elif random_number % number_of_players == 1:
    goes_first = p2
elif random_number % number_of_players == 2:
    goes_first = p3
else:
    goes_first = p4

print(f"{goes_first} goes first")

print(f"The next number is {next_number}")

Output:

How many players are there?4

Random number is 99
Number of players is 4

Player 4 goes first
The next number is 894

1 Like

I did it with C++

894 % 4 = 2 so the answer is Player3

next number = 589

1 Like

589 % 4 = 0.25
0.25 * 4 = 1

589 % 4 = 1

Next Number = 76

1 Like

with C

return Player1

Next Number = 7926

1 Like

C

#include <stdio.h>

int main(int argc, char** argv) {
  printf("Player %d goes first\n", 7926 % 4 + 1);
  return 0;
}

Output:

Player 3 goes first

Next number 7510

JS
캡처11

Result : player3

Next number : 6321

Code written in C++

#include <iostream>
#include <cstdlib>
#include <ctime>

// Function to calculate player name based on remainder
void printPlayerName(int num) {
    int remainder = num % 4;
    switch (remainder) {
        case 0:
            std::cout << "Player 1";
            break;
        case 1:
            std::cout << "Player 2";
            break;
        case 2:
            std::cout << "Player 3";
            break;
        case 3:
            std::cout << "Player 4";
            break;
        default:
            std::cout << "Invalid number";
            break;
    }
    std::cout << std::endl;
}

int main() {
    // Declare three integer values
    int num1 = 63;
    int num2 = 6321;
    int randNum = rand() % 10000; // Generate a random number between 0 and 10,000

    // Calculate remainder and output player for num1
    printPlayerName(num1);

    // Calculate remainder and output player for num2
    printPlayerName(num2);

    // Output random number
    std::cout << "Random number: " << randNum << std::endl;

    return 0;
}

Result for default value: Player 4
Result for previous value in this thread: Player 2

Next Number: 9383

is this ok?

63 % 4 = 3

Since our player numbering starts at 0 (meaning 0 remainder), the player at remainder 3 is the 4th player! So Player 4 goes first.

in C++:

#include <iostream>
using namespace std;

int main() {

    int remainder = 63 % 4;
    cout << remainder;
    
}

The calculator makes this trickier for me to translate the answer to the logic.

63 / 4 = 15.75. We are left with .75 of a number, so 3/4 around our circle lands us at 3. This is our 4th Player.

New Number: 82

Working on learning Powershell scripting so I’m crossing streams so to speak…

Ugly but I wanted to try ‘switch’, and it works!

Privacy & Terms