public static int distance ( int a , int b , int N ) { return ( a > b ) ? Math . min ( a - b , b + N - a ) : Math . min ( b - a , a + N - b ) ; }
Returns the distance between the supplied to numbers modulo N .