Determine the position of the third person on regular N sided polygon | Function to find out the number of that vertices ; Another person can 't stand on  vertex on which 2 children stand. ; calculating minimum jumps from each vertex . ; Calculate sum of jumps . ; Driver code ; Calling function
function vertices ( N , A , B ) { var position = 0 ; var minisum = Number . MAX_VALUE ; var sum = 0 ; for ( var i = 1 ; i <= N ; i ++ ) { if ( i == A i == B ) continue ; else { var x = Math . abs ( i - A ) ; var y = Math . abs ( i - B ) ; sum = x + y ; if ( sum < minisum ) { minisum = sum ; position = i ; } } } return position ; } var N = 3 , A = 1 , B = 2 ; document . write ( " " + vertices ( N , A , B ) ) ;