Math - Remainders - Challenge

// Section 1 - 06 : Remained for 63%4 this will be 3, because 63 is one digit away of 64, which has 0 remainder
// Using NodeJS

// Using internal function '%'
console.log(`63 % 4 = ${63 % 4}`)

// In steps
let x = 63 / 4
let remainder = x - Math.floor(x)
console.log(`Steps ${Math.floor(remainder * 4)}`)
1 Like

Remainder is 3 so the player set to remainder 3 will go first.

Since we always start at 0, that would make the player with remainder 3 player 4

Someone please correct me if this is wrong! =)

1 Like

Player 3 will go first. 4 goes into 60 15 times, leaving a remainder of 3.

To duplicate this in Python, I used the following:

import random

next_player = random.randint(0,100) % 4
1 Like

@FedPete, @Ajai_Raj
Nice work converting this challenge into code.
Don’t forget that you also need to add 1 to your calculation to get the correct player. If you just use the remainder then you’d be selecting between players 0-3 rather than 1-4.

2 Likes

63 % 4 via calculator

63/4 = 15.75
.75 * 4 = 3

via code (python since I’m currently on my laptop and don’t have visual studio installed)

>>> i = 63%4
>>> print(i)
3
>>>

So player 4 would go first:

The most recent number I see is 93 so:
93%4 via calculator
93/4 = 23.25
.25 * 4 = 1

via code

>>> i = 93 % 4
>>> print (i)
1
>>> 

So player 2 would go first.

For the next in line: 76

1 Like

For the challenge…
63 % 3 = r 3
remainder of 3 would make it player 4

in a code form

playerAmt = 4
startPlayer = 1 – default

rand % playerAmt = x
startPlayer = startPlayer + x

– startPlayer would equal 4

ok for 76…

76%4 – with calculator
76/4 = 19
remainder is 0 so plater one starts the game

randAmt = 76
playerAmt = 4
startPlayer = 1 – default

randAmt % playerAmt = x
startPlayer = startPlayer + x

– startPlayer would equal 1

next number to try 53

1 Like

Player 4 goes first.

93

1 Like

Player 2 Goes First!

74

1 Like

In code theory when we had a really big number I used to find remainders by subtracting the divisor from the dividend. 63-4-4-4-4-4-4… until the result falls between the range of the divisor or 15*4=60 and remains 3. I don’t know if I got myself across but I know it can be a really time saver

Player 3 goes first!

29

Player 2 goes first!

46

Player 3’s turn
// here’s the code that I used https://gist.github.com/donyd/1275c2ea2ef364325b3344261775d8c9
Next random number is: 69

Nice.

When 69 is our randomly generated number, Player 2 would go first. 69 % 4 = 1, which is the spot on the circle assigned to Player 2.

Who wants to give 72 a try?

if 72 is the random number it will be 18 and so player 3 will start
72 % 4 = 18 which is on spot number 2

the next number will be 87

1 Like

Hi everybody!

87
87 % 4 = 3 ----> Player 4

Next number: 666

I wrote C# to calculate the answer:

        var playerCount = 4;
        var seed = System.DateTime.Now.Millisecond;
        var random = new System.Random(seed).Next(playerCount, int.MaxValue);
        var whoseTurn = (random % playerCount) + 1;
        System.Console.WriteLine($"It is player #{whoseTurn}'s turn.");

Last post’s chain number was 666 (thanks Daniel_Zuvela).
666 % 4 = 2, so the code should output “It is player #3’s turn.”

Next number: 93

Was angry because the result of my code was going to zero, but I did 64%4=0, and 63%4=3, lool

93 % 4 = 1, so player 1’s turn

Next number: 57

57%4 = 1
Player 2’s turn

Next number: 73

73%4=1
Player 2’s turn

Next number: 173

Privacy & Terms