Generalized formula to move in a circle

Revision en5, by hellomoto, 2020-10-22 20:45:09

As we know if we have an array of size n, let's say a0, a1, a2, ......, an-1. we can preform x move clockwise with ((ai + x) % n) and anticlockwise with ((ai — x) % n + n) % n.

Can we generalized for clockwise and anticlockwise for the index i to j? So what will be the formula if we want to circle from ai to aj in an array(0 indexed and size of the array is n)?

Tags #math

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en6 English hellomoto 2020-10-22 20:46:37 190
en5 English hellomoto 2020-10-22 20:45:09 190 Reverted to en1
en4 English hellomoto 2020-10-22 20:40:51 172
en3 English hellomoto 2020-10-22 20:36:25 10
en2 English hellomoto 2020-10-22 17:28:44 8
en1 English hellomoto 2020-10-22 17:12:58 413 Initial revision (published)