// in c++
int main()
{
int nextNumber = 429;
std::cout << “Its player " << (nextNumber % 4 + 1) << " turn.” << std::endl;
}
Next number is 394
Cheers lads xD !!
Next number is 394
So, from previous thread: 394
Here’s my code in C#:
public void AnnounceAssignedPlayer(int input, int maxPlayer)
{
int assignedPlayer = input % maxPlayer;
Print($"This round, player {assignedPlayer + 1} go first!");
}
AnnounceAssignedPlayer(input:394, maxPlayer:4);
And the result is: “This round, player 3 go first!”
So, onto next person whom will continue after me: “Your next random number is: 140”
Ref:
public void ForNextThread()
{
int input = new System.Random().Next(69, 420);
Print($"Your next random number is: {input}");
}
PS: I thought that code block with assigned language was just a discord thing, apparantly not. So, whoever after me if you want to be fancy and writing code block use ```[language] on line above and below your code use just “```”! Cheers!
For example: ```cs to show code in CSharp
So, 140? Sounds great to me! I did the math on paper, and 140 % 4 is 35 even, so the answer will be Player 1 goes first! Just to be sure, I ran the math using an online C# compiler (my main language), and here was the results:
4 Players are playing, and 140 was randomly rolled to go first.
If 0 = Player 1, 1 = Player 2, 2 = Player 3, and 4 = Player 4, who goes first?
Player 1 goes first!
And here’s my code I used to solve for it:
int playerRoll = 140;
Console.WriteLine($"4 Players are playing, and {playerRoll} was randomly rolled to go first.");
Console.WriteLine("If 0 = Player 1, 1 = Player 2, 2 = Player 3, and 4 = Player 4, who goes first?");
int firstPlayer = playerRoll % 4;
Console.WriteLine($"Player {firstPlayer + 1} goes first!");
The next number to solve is 571, so enjoy!
Thank you for the number!
571
Here is my calculation:
571 / 4 = 142.75
0.75 * 4 = 3.
That means Player 4 goes first this round.
And here is my code:
int rolledNumber = 571;
int playerTurn = rolledNumber % 4;
if(playerTurn == 0)
{
Console.WriteLine("PLAYER 1");
}
else if(playerTurn == 1)
{
Console.WriteLine("PLAYER 2");
}
else if (playerTurn == 2)
{
Console.WriteLine("PLAYER 3");
}
else if (playerTurn == 3)
{
Console.WriteLine("PLAYER 4");
}
The next random number is:
14
Thanks for the number 14
!
Here’s my calculation:
14 ÷ 4 = 3.5
0.5 × 4 = 2
Therefore player three goes first!
My code:
using UnityEngine;
public class Remainder : MonoBehaviour
{
[SerializeField] private int magicNumber = 14;
[SerializeField] private int numberOfPlayers = 4;
private Player[] players;
public void Start()
{
GeneratePlayers(numberOfPlayers);
Player startPlayer = GetStartPlayer();
startPlayer.StartTurn();
}
private void GeneratePlayers(int numberOfPlayers)
{
players = new Player[numberOfPlayers];
for (int i = 0; i < numberOfPlayers; i++)
{
Player newPlayer = new Player(i + 1);
players[i] = newPlayer;
}
}
private Player GetStartPlayer()
{
int playerIndex = magicNumber % players.Length;
return players[playerIndex];
}
private class Player
{
private int _playerNumber;
public Player(int playerNumber)
{
_playerNumber = playerNumber;
}
public void StartTurn()
{
Debug.Log("Player " + _playerNumber + " started their turn.");
}
}
}
Your next number is:
81
81 % 4 = 1
81 ÷ 4 = 20.25
.25 * 4 = 1
Therefore Player 2 goes.
Next number: 29
Thanks for 29
29 / 4 = 7.25
0.25 * 4 = 1
Player 2 goes first
Next Number is 117
Thanks for 117.
117 % 4 = 1
or
117 / 4 = 54.25
0.25 * 4 = 1
Player 2 goes first.
Your next number is 571
Thanks for 571.
571 % 4
571 / 4 = 142.75
0.75 * 4 = 3
Player 4 goes first.
Your next number is 69
63 / 4 = 15.75
.75 * 4 = 3
It’s the 4th player’s turn
My number is very forgiving (69)
69/4 = 17.25
.25 * 4 = 1
It’ll be the 2nd player’s turn
Your next number is 24
24/4 = 6
Remainder = 0
It is Player 1’s Turn
Your next number is 41
New number is: 41
41 % 4
41 / 4 = 10.25
10.25 - 10 = 0.25
0.25 x 4 = 1
Answer: Since the remainder is 1, it is player 2’s turn.
THE NEW NUMBER SHALL BE: 784
New number is 784
784 % 4 = 196
The remainder is 0, so it’s 1’s turn.
The new number is 146
Given number: 146
146 / 4 = 36.5
0.5 * 4 = 2
2 + 1 = 3
Player 3 starts.
public class MathRemainders : MonoBehaviour
{
[SerializeField] private int _players = 10;
private int _randNum = 0;
private void Start()
{
RollRandomNum();
Result();
}
private void RollRandomNum()
{
_randNum = Random.Range(1, 10 * _players + 1) % _players;
}
private void Result()
{
Debug.Log($"Player {_randNum + 1} goes first!");
}
}
The new number is 893.
893 % 4 = 1
Player One’s Turn!
using System;
using UnityEngine;
using Random = System.Random;
public class MathLearning : MonoBehaviour
{
private void Update()
{
// right click
if (Input.GetMouseButtonDown(1)) PlayerTurn();
}
void PlayerTurn()
{
// generate a random number between 0 and 1000
Random r = new Random();
int number = r.Next(0, 1000);
int FinalNumber = number % 4;
Debug.Log("The randomly generated number: " + FinalNumber);
// should be self explanatory.
switch (FinalNumber)
{
case 0:
Debug.Log("Player ONE'S turn!");
break;
case 1:
Debug.Log("Player TWO'S turn!");
break;
case 2:
Debug.Log("Player THREE'S turn!");
break;
case 3:
Debug.Log("Player FOUR'S turn!");
break;
}
}
New number: 205
As everyone has already done it, the remainder is 3 so player 4, and my random number is… let me think… 39.
63/4=60 with a remainnder of 3 …so player 4.
Previous Number: 39
39/4=36 with a remainder of 3…so player 4.
Next Number: 51
63/4=15.75
0.75x4=3 (remainder)
Turn for player 4.
51/4=12.75
0.75x4=3. Player 4 again.
Next Number: 27
27/4=6.75
0.75*4=3
Next Number: 52
and i did mine in C#