Learning and Understanding Modulus
This winter break I wanted to work on concepts that I needed a a more thorough understanding in. I always had a hard time understanding the concept of a modulus function in code. While I was going over Yiting’s and my final project, I noticed a number of lines in which Yiting preferred using the modulus function on our rotary encoder to pick the layers in the Indian and Chinese dishes.
I always had the the tendency to mix up the concept of modulus with regular division method. And while that maybe true, I realized that the division was not the remainder of the divisor, but it was the remainder of the dividend.
for eg.
0%5 = 0
1%5 = 1
2%5=2
3%5=3
4%5=4
5%5=0
6%5=1
This is an example from The Coding Train’s video, Guest Tutorial #6: The Modulo Operator with Golan Levin:
Next Steps: Applying the concept of modulus functions in code to understand the nature of the function