In reply to:


I think that the problem with Bitt's solution (or, strictly, my implementation of it) is that the C/C++ % operator does odd things with negative numbers.




Yeah, that's why my solution has a +6 instead of a -1.