logoalt Hacker News

ludwiktoday at 6:59 AM2 repliesview on HN

Shouldn't the code say:

    position = (position + direction + 1) % 12;
Or have I misunderstood something?

Replies

nulptrtoday at 7:56 AM

The +12 there is so that % works correctly (ie the number never becomes negative)

LiamPowelltoday at 7:05 AM

The +12 is to keep the number positive. The direction contains the movement so a +1 wouldn't make sense.