I require a function dist( a, b ) // 0 ≤ a,b < 12 which returns the shortest (absolute ie +ve) distance ala clock arithmetic, using modulo 12.
So for example,
dist( 1, 2 )
= dist( 2, 1 )
= dist( 11, 0 )
= dist( 0, 11 )
= dist( 0.5, 11.5 )
= 1
EDIT: while this can easily be done with a bit of hacking around, I feel that there must be some intuitive solution, may be using fmod and modulo 6
This question does not show any research effort;...
. What was your question?I require a function... [and some various examples]
Was it clear that you've even attempted finding out a solution for yourself? Well you haven't shown it. What you effectively have done was aplzsendtehcodez
question. This might not have been your intention, but you didn't make your case very clear. – Chambrayplzsendtehcodez
, but it's a three-liner so w/e. – Croutonplzsendtehcodez
questions on this site. – Crouton