Ad
  • Custom User Avatar

    This is an old comment, but just in case someone else is puzzled reading it... The % operator in C and C-based languages like C++, Java and C#, is not a true "modulo operator". It's a remainder from integer division that truncates toward 0, so that nonzero values of x % y will have the same sign as x.

    Many other languages use a remainder from floor division, where nonzero values of x % y have the same sign as y. So n%10 always gives the least positive remainder from dividing n / 10. In this case, that makes:

    -1 % 9 == -1  .... in C, C++, Java, C#
    -1 % 9 ==  8  .... in Python, Ruby, APL 
    

    This problem is one of the rare cases (in my experience) where C-style remainders simplify code. Usually there's no difference, but when there is I find that I have to adjust for the difference more often in C than in Python or Ruby.

  • Custom User Avatar

    oh, that is weird let me know if you figure why that is

  • Custom User Avatar

    What are you talking about? I just tested with 0 and it passes just fine.