CSP U7 L3 level 9

This is my first year teaching an AP course, and I must admit that I have never heard of n mod n or n % n. I have searched and struggled to find why 2 % 3 is 2 and why 2 % 4 is 2. Not being a math person, I thought that you couldn’t divide 2 by a larger number. There is no remainder! Please help.

Code from U7 L3 level 9 example solution:
// Make sure students are understanding the concept of how %
// is tied to the remainder
// Example
console.log(5%2);
console.log(1);
console.log("");

// console.log your answer - check that the two lines match in the console
console.log(2%3);
console.log(2);
console.log("");

// console.log your answer - check that the two lines match in the console
console.log(10%2);
console.log(0);
console.log("");

// console.log your answer - check that the two lines match in the console
console.log(2%4);
console.log(2);
console.log("");

// console.log your answer - check that the two lines match in the console
console.log(7%1);
console.log(0);
console.log("");

Think of it as a transformation from an infinite range of numbers to a finite set of categories. You already know one such transformation. Even and odd. All numbers can be transformed into even or odd.

Start at 0 let that be the quintessential even. Counting up, every other number is even. Starting at 1 let that be the odd numbers. From 1 every other number is odd.

Even numbers are on team 0. Odd numbers belong to team 1. So given any number, we can figure out if it is on team 0 or team 1. Let’s also say that for every 2 numbers we have a 0 and a 1. That is modulo 2.

So now let’s go to modulo 3. We start with three teams instead of two. Namely, 0, 1, 2. Obviously, 0 is on team 0; 1 is on team 1; 2 is on team 2. And now we count up in groups of 3.

Let’s count to 5 using modulo 3: 1, 2, 0, 1, 2. So 5 modulo 3 is 2 because 5 is on team 2.

Let’s count to 8 using modulo 3: 1, 2, 0, 1, 2, 0, 1, 2. So 8 modulo 3 is also on team 2. Of course because it is 3 more than 5 which is 3 more than 2.

Let’s count to 10 using modulo 3: 1, 2, 0, 1, 2, 0, 1, 2, 0, 1. 10 is on team 1. That makes sense because 10 is 3 greater than 7, which is 3 greater than 4, which is 3 greater than 1 and 1 is home base for team 1.

It’s like dividing up the jelly beans when you have 3 kids with their hands out. Who got the last jelly bean?

We could also say that 10 = 1 + 3 x 3. You might even say 10 / 3 is 3 with a remainder of 1. These are just mathematical constructs to help us figure out which number is on what team.

Can you guess what happens when you go to modulo 4?

Hi @evruss ,

On top of Don’s helpful illustration, here’s a visual tool called the Modulo Clock from an older version of code.org’s CSP curriculum: Code.org - CSP Unit 4 - Big Data and Privacy ('19-'20): Public Key Crypto #5

As a side note, I try to be careful about the language I use when referring to abilities - both for my own sake and others (students’). By identifying one as a “math person”, it’s implied that the ability is embedded in one’s identity, as opposed to something that can be influenced by factors under our control. Why try to get better if it’s just part of who I am? (Not saying this is your case, as you’re obviously taking action to learn by consulting this forum.) No doubt our abilities are connected in some way to innate abilities, but I prefer to use language that leaves more room for acting on improvement (in this case, perhaps “Not being someone with a strong math background” or even “Being someone who has struggled with math” - not necessarily making it positive, but at least not implying identity or future performance - or go the positive route and add “… yet” to the end of statements but that’s a bit much for my personal tastes heh).

Not trying to tell you how you should speak - but something I think worth considering if it’s something you hadn’t come across before.

Thank you both for helping. I like to thoroughly understand a lesson before teaching. I have been an English teacher for over 20 years and am amazed at how much math I have had to learn in this year! I am learning to love programming by the way (just not the mathematical aspects) :relaxed:

1 Like

Mod is tricky. Whenever my students have a question on mod, we go back to long division. If I start with 3 mod 2:
image

So 2 mod 4 would look like this:
image

That seems to help my students “see” it.

2 Likes

Okay, that is so much clearer. I taught the lesson today and just used the Modulo Clock link to guide my explanation. They did not understand the 2%4 or 2%3, but I think the long division explanation will help them out tomorrow. Thank you!

1 Like