Circular Math Calculation Formula

Circular Math Calculation Formula

Hi

i have a need to do a rotational calculation between a set of values

FOr example

Lets assume the below values assigned to the Location

Location-A= 1
Location-B=2
Location-C= 3
Location-D= 4
Location-E= 5

IF I PASS a query asking : what is the distance between Location-A to Location-D - : It should give 4th step


if i pass a query asking : what is the distance between Location-E to Location-C : It should give 4th Step

if i pass a query asking : what is the distance between Location-E to Location-D : It should give 5th Step


I need a script to use as a function so if i feed in 1st location and 2nd location it should return the step position

ANy help be really great