Comment on If I hear "% is a mathematical operator" one more time...
Rivalarrival@lemmy.today 5 days agoModulo is much easier to understand with clocks.
Suppose It is currently midnight. What time will it be in 3 hours? 3 mod 24 = 3. It will be 03:00
What time will it be in 27 hours? 27 mod 24 = 3. It will be 03:00 we go through a whole day (24 hours) to get back to midnight, then another 3 hours.
What time will it be 48 hours from now? 48 mod 24 = 0. 48 hours from midnight will be midnight.
What time will it be 6 hours from now? 6 mod 24 = 6.
Conceptually, X mod Y means that instead of 24 hours per day, we are splitting the day into Y “hours”, labeled 0 to Y-1. We start at 0, and pass through X “hours”. X mod Y is the “hour” we finish up in at the end. 5 mod 2 means we have a 2-hour day, with hours 0 and 1. We pass through 5 of those hours. When we finish, are we at hour 0 or hour 1?