Skip to content

Another good use for mod

Got to admit that mod is one of those topics that I have trouble getting across to my students. Not the idea of what it is and how to do it, but the purpose. The classic isOdd / isEven lab works. It can even be extended a bit into a isDivisible lab. And the College Board has helped with their free response questions on digit counter and having to keep an array in bounds as it loops from one end to the other. But even those are not all that real world.

Yesterday I came across a file upload plugin for Vanilla Forums that puts mod to use in a real world way. When a file is uploaded, the file is put into one of 20 folders based on the file number % 20.

The normal way of doing this is counting the number of files in each directory and moving on to the next folder if there are too many. The mod method this plugin uses keeps each folder with about the same number of files.

What I’m thinking is a CS Unplugged type lab where you give the students a stack of numbered cards along with 7 or 8 boxes numbered 1 through the count. Then they put the cards into the boxes based on their mod result. So if they had 8 boxes they’d put card 14 into box 6.

Any other tips for working with mod that makes sense to your students?

Published inComputer Scienceteaching

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *