Modulo is a math operation that finds the remainder when one integer is divided by another. In writing, it is frequently abbreviated as mod, or represented by the symbol %.

So % finds the remainder after dividing by 2. So what I said and what the book says are the same. I note that the book is also applying the mod to the row and column values before the total is found. mod 2 division will 'detect' even and odd numbers .

The use of % more than once is necessary. If you just had

color = (row % 2) + (column % 2)

There are the four cases are 0 + 0 = 0; 0 + 1 = 1; 1 + 0 = 1; and 1 + 1 = 2

The last answer would not give a 1 or 0 so would generate an error.

But I think this would work:

color = ( row + column ) % 2

Perhaps you could try it.

There's a short page about modulo arithmetic here: https://www.mathsisfun.com/numbers/modulo.html

Bob

]]>for (1,1)

(1 % 2) + (1 % 2) = 1 + 1 = 1 white, is this the way I apply by numbers? am I correct

and please why the book in the end used additional mod :

color = ( (row % 2) + (column % 2) ) % 2

look he used again %2!! he found sum of reminders than take mod 2 again? why? and where locations should I apply this formula only in the last row? because he said "fourth entries" is he mean the last row, isn't enough to use only (row%2) + (col%2)

]]>This calculation will achieve that:

total = col + row

value = total/2 - INT(total/2) where the division is a normal division with possibly a remainder, and INT yields the integer value of the answer ie. discards the fraction.

Look what happens when total is even and when it is odd.

total even: value = <another integer> - <same integer> = zero. This happens because there is no fractional part to discard.

total odd: value = <an integer + 0.5> - <same integer without the 0.5> = 0.5.

So the value calculation enables you to detect ODD and EVEN as needed.

Bob

]]>I have the question and the solution but it's not understandable completely expect I know that we need mod 2 (ODD and even) in my solution.

A robot needs to tile a floor with alternating black and white tiles. Develop

an algorithm that yields the color (0 for black, 1 for white), given the row and

column number. Start with specific values for the row and column, and then

generalize

////// solution of the book start

Solution of the book :

Clearly, the answer depends only on whether

the row and column numbers are even or odd,

so letâ€™s first take the remainder after dividing by 2. Then we can enumerate all expected

answers:

In the first three entries of the table, the color

is simply the sum of the remainders. In the

fourth entry, the sum would be 2, but we want

a zero. We can achieve that by taking another

remainder operation:

color = ( (row % 2) + (column % 2) ) % 2

////// solution of the book Ended

pls explain the book solution only I want to understand it step by step I didn't understand what he mean by dividing

note that the dividing here is integer division ex : 3/2 = 1 not 1.5 because it discard the fractional part

I didn't understand the solution from beginning like " first take the remainder after dividding by 2"

which reminder? and what number we are dividing it by 2 ?

the solution is confusing be and ambiguous