This Was Not a Secret

Sometimes I think that Ritchie is an evil God. He knows everything that is going on in his base at any given time, how to program and control machines, and how to get things done in a post-apocalyptic world. What else could you need? That's why, when he surprised me with a visit to my room one day, my first thought was that he knew all about my secret dealings with Noname.

"Hi, Teo. How's it going?" Ritchie asked.

Quite well in fact; I've learned forbidden knowledge in the basement, made a deal with a machine controlled by you, and am desperately trying to leave this madhouse, I thought.

"Hi, Ritchie! I'm fine, how are you?" I said instead.
"Fine, thanks," he replied. "You have an opportunity to get a huge raise. You have a chance to move up to Wonderland."
"Wonderland?" I asked, hoping it sounded as if I had never heard the term.

"It's the biggest resistance base on Earth. The best human programmers are there."
"Okay... but why me, Ritchie? You never seemed to like me much."
"And I still don't. But current circumstances require one more person. To put you in that slot, I need to train you more."

Modulo

"You already know a lot about math operations, Teo, including operators such as +, -, *, and /. But there is one very important operation that you haven't encountered yet: the modulo operation. We use a % sign for it. If the operands are integers, the modulo returns the remainder of dividing x by y," Ritchie said.

modulo

"What's a remainder again?" I asked, "It's been a while since I was in math class and..."
"Come on, Teo," Ritchie interrupted. "Maybe you aren't the right fit for the Wonderland promotion." He sighed before continuing. "Ok, listen. Imagine you have 13 candies and 4 equal boxes. Each box must contain 4 candies. How many full boxes can you get?" Ritchie asked.
"3 boxes."
"Correct. And how many candies would not be packed?"
"One candy will be left because you can't have a partially filled box," I replied.

"There you go! This leftover, or 'remainder,' is a result of a modulo operation. 13 modulo 4 will be 1. You can write it this way: 13 % 4 = 1. That's exactly what you've done inside your brain. Here is a formal definition of the remainder that is returned by the modulo operation of x and y:"
 q = x / y
r = x % y
then
x = q * y + r.
"So, in our example: 13 = 3 * 4 + 1."
"We'll only focus on modulo operations with integer types," Ritchie said. "Here is an example:"

result = a % b

"Ritchie, this seems complicated. When would you actually use this?" I asked.
"The modulo operation is extensively used in programming," Ritchie replied. "For example, say you need to write a program to sort students into classrooms. You have 3 classrooms, and the user enters the number of students as input to your program. Before going through the trouble of sorting the students, it would be helpful to first check if they can be distributed equally or not by using the modulo operation. Here is an example that I've written:"

students_number = int(input())
left_to_fit = students_number % 3

if left_to_fit == 0:
    print("Can distribute students equally.")
else:
    print(f"Can't distribute students equally. Students left: {left_to_fit}")

"Okay, I see now," I said, "but why in that example do you compare the result of the modulo operation with zero, Ritchie?"
"If the result of a modulo b is zero, it means that a is divisible by b. Sometimes, the power of using the modulo operator is just determining if a number is divisible by another. Divisible means if a is divided by b, the result is an exact whole number. For example, 12 is divisible by 2, and 6 is divisible by 3. In contrast, 13 is not divisible by 4. Do you follow?" Ritchie asked.
"Sure, I get it," I said.
"Ok, good. Try this task on your own."

math

This first task was easy enough, but my mind was swimming with all this new information. In school, we were taught things around the concept of the modulo; the remainder, and how to divide... but never the modulo itself. In programming, it turns out the modulo is an important operation that helps to understand whether one number is divisible by another. Who would have thought that we spent all that time in school actually finding the remainder, but in the future, we'd be more concerned about whether there was a remainder?
Ritchie proposed a couple of new tasks while I was deep in thought.

"Now I think you have a chance at being accepted in Wonderland. Good job, Teo." Ritchie said.
"Thanks," I said, "after all this, I need a serious coffee break."

get back to school