The remainder that goes negative
transcript
What is minus one modulo six? Python says five. Java says minus one. Your answer depends on the language you chose.
The same expression gives two answers. Python never returns a negative remainder. The other three keep the sign of the first number. So test a negative total in every language.
A rotation adds up its presses. The total can be negative. A negative start crashes the string cut. A crash like that is easy to miss in Python. Always check the sign before you cut.
The fix has two steps. Take the remainder, then add n. Take the remainder again. Now the start is from zero to n minus one. It works in all four languages.
The presses can reach a billion each. There can be a hundred thousand of them. So the total needs sixty-four bits. Then take the remainder, as in the fix.
Never trust a negative remainder. Fix it in one line. Full breakdown in the lecture.