# Math - Remainders - Challenge

In this lecture we looked at how to find the remainder after division and how this can be useful for decision making.

Your challenge is to imagine a 4 player game, and figure out who goes first.

Player 1 is assigned the remainder 0.
Player 2 is assigned the remainder 1.
Player 3 is assigned the remainder 2.
Player 4 is assigned the remainder 3.

To decide who goes first, find the remainder of 63 ÷ 4.

Pop your answer below and then set a new integer (to replace 63) for the next person in the chain to try.

3

72

The question is a little unclear as it says find the remainder…
Remainder 3 so player 4

1 Like

Is 3 the remainder of the starting player?

72

Player 1 (remainder 0).

Next number: 55

1 Like

55

Player 4 (remain 3)

Next Number: 93

1 Like

93

Player 2 (remainder 1)

Next number: 127

1 Like

127

Player 4 (remainder 3)

Next number: 24

1 Like

24

Player 1 goes first (remain 0)

Next number: 42

1 Like

The answer is :

Player 3 goes first

After that I changed the counter to 68 so player 0 could play

with calculator :

with code (in C) :

I just picked a number because the chain broke: 15

On paper: 15%4 = 3 Remainder 3
In Python (Spyder IDE):

Player 4 may play.

Next number: 19

1 Like

The remainder for the first integer of 63 % 4 = 3 .

This would mean that Player 4 is the first player to start.

Should the next integer be 42, then remainder would result to 2, making Player 3 the next player to begin.

1 Like

To answer the first question, my remainder was 3 with Player 4 going first.

Code wise I did the following:

void UMathProblems::BeginPlay()
{
Super::BeginPlay();

``````int32 RandomNumber = FMath::RandRange(0, 4);

switch (RandomNumber%4)
{
case 0:
UE_LOG(LogTemp, Warning, TEXT("Player ONE goes first."));
break;
case 1:
UE_LOG(LogTemp, Warning, TEXT("Player TWO goes first."));
break;
case 2:
UE_LOG(LogTemp, Warning, TEXT("Player THREE goes first."));
break;
case 3:
UE_LOG(LogTemp, Warning, TEXT("Player FOUR goes first."));
break;
}
``````

}

If you want to debug you can add UE_LOG(LogTemp, Warning, TEXT("%i"), RandomNumber%4); after line 5 of this code.

2 Likes

To answer the question, my remainder was 3 so player 4 would start
If the next number was 64 the remainder would be 0 so in the next round player 1 would start

1 Like

I did mine in Java:

``````        int playerDeterminer = 63;
int currentPlayer = 0;

System.out.println(playerDeterminer + " % 4 = " + (playerDeterminer % 4));

switch (playerDeterminer % 4) {
case 0:
currentPlayer = 1;
break;
case 1:
currentPlayer = 2;
break;
case 2:
currentPlayer = 3;
break;
case 3:
currentPlayer = 4;
break;
}

System.out.println("Current Player is: " + currentPlayer);
playerDeterminer = 78; // Setting a 'new' number
``````

Here’s the output:

``````63 % 4 = 3
Current Player is: 4
``````
2 Likes
``````void Start()
{
var fixedValue = 63;
var randomValue = Random.Range(0, 100);
var players = 4;
var offset = 1;

Debug.Log("value " + fixedValue);
Debug.Log("Player " + GetStartingPlayer(fixedValue, players, offset) + " starts the game.");
Debug.Log("value " + randomValue);
Debug.Log("Player " + GetStartingPlayer(randomValue, players, offset) + " starts the game.");
}

private int GetStartingPlayer(int value, int players, int offset)
{
return (value % players) + offset;
}
``````

1 Like

As i can not see the next number into the thread i am going to multiply 63 * 2 so next number is 126 and the answer to the challenge is:

Player two goes first in this case

next number 126 * 2

1 Like

This was fun. I experimented a little and added some randomness to the second check.

If I understand right, the number above me is 252 (126 * 2). So 252 / 4 = 63 with no remainder. So 0 would be player 1’s turn.

For the next person in the chain: 93 / 4.

63, so, player 3 will go first.

Then a random number, within the range of 1, 100.

C#

The operations I did on the calculator:
(63 % 4) = ((63 / 4) - 15) * 4 = 3 so player four gets the first turn

my code to solve this assignment:
using UnityEngine;

public class MathCourseTests : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
int remainder = 63 % 4;
Debug.Log("The remainder of 63/4 is: " + remainder);
Debug.Log(“So player " + (remainder + 1) + " goes first”);
}
}

1 Like

I liked the option presented in the tutorial. The way I do it usually is in my head as an exercise in multiplication.

63 mod 4 would be 4*15=60 which gives me the closest I can get without going over so now I know that 63 - 60 = 3 and that becomes my remainder.

1 Like