News for hackers. Stuff that matters.
Re:Ask HN: Beginner lost in modular airthmetic division by jackallis on Thursday September 13, 2018 @03:15PM (#17981512)
so 5 % 6 = 5?
Re:Ask HN: Beginner lost in modular airthmetic division by cimmanom on Saturday September 15, 2018 @01:44AM (#17993161)
Yup. The modulo operator simply always returns the remainder after division.

5 % 6 = 5

11 % 6 = 5

12 % 6 = 0

13 % 6 = 1

837 % 6 = 3

It’s especially useful for repeating sequences:

> for x in [0, 1, 2, 3, 4]:

      print(“odd” if (x % 2) else “even”)

 even

 odd

 even

 odd

 even
> for x in [0, 1, 2, 3, 4, 5]:

      print(“pah” if (x % 3) else “oom”)

 oom

 pah

 pah

 oom

 pah

 pah