The arithmetic solution to this is relatively simple.. we're talking modulo here:
the solution will be:
return i % N;
this should produce the same results for your adjusted index.
When I ran a few calculations on the modulo operator through wolfram-alpha, I got following results:
for \$F(x) = x \mod 3\$
\$ 5 \mapsto 2 \$
\$ 4 \mapsto 1 \$
\$ 3 \mapsto 0 \$
\$ 2 \mapsto 2 \$
\$ 1 \mapsto 1 \$
\$ 0 \mapsto 0 \$
\$-1 \mapsto 2 \$
\$-2 \mapsto 1 \$
\$-3 \mapsto 0 \$
the pattern we see here is exactly what you describe.