- Joined
- Sep 20, 2022
- Messages
- 317
- Reaction score
- 41
Code:
pseudocode
M is an integer constant > 0
S is an integer constant >= 0
d = array of M zeroes
d[0] = 1
i = S % M
WHILE i != 0
d[i] = 1
i = (i + S) % M
I'm having trouble proving this. I suspect I'm overlooking (senior moment) something obvious.
Its important because if true, I can rotate any array any distance with only M (size of array) assignments, and no extra memory.