15 ms·
So 8 divided by 4 is 1 with a remainder of 4?
by shasta 11y ago
So 8 divided by 4 is 1 with a remainder of 4?
- TheLoneWolfling 11y agoNo. Two with a "remainder" of 4. Ideally I'd call it by another name to avoid confusion (and the implication that x == x//y * y + x % y - although this is often incorrect in the case of negative values anyways), but I do not know what other "better" name to call it. Think about it. If you have a series of bins with 4 items each, and you ask someone to grab the 8th item, where do they go? To the 4th item of the second bin.
- shasta 11y agoLooking at division and mod as a pair finding group and subgroup indices is interesting. For zero based indexing, we want division to round down and the usual zero-based mod. So Group(8,4) = 8/4 = 2, Index(8,4) = 8 % 4 = 0. The invariant is x == x/y * y + x % y. With one based indexing, we want division to round up and want the modulo operator you're describing. So Group(8,4) = 8/'4 = 2, Index(8,4) = 8 %' 4 = 4. The invariant is x == (x/'y - 1) * y + x %' y.