Find out the correct position of the ball after shuffling | javascript implementation of the above approach ; Function to generate the index of the glass containing the ball ; Change the index ; Change the index ; Prvar the index ; Driver Code ; Storing all the shuffle operation
M = 3 ; N = 2 ; function getIndex ( n , shuffle ) { for ( i = 0 ; i < 3 ; i ++ ) { if ( shuffle [ i ] [ 0 ] == n ) n = shuffle [ i ] [ 1 ] ; else if ( shuffle [ i ] [ 1 ] == n ) n = shuffle [ i ] [ 0 ] ; } document . write ( n ) ; } var n = 3 ; var shuffle = [ [ 3 , 1 ] , [ 2 , 1 ] , [ 1 , 2 ] ] ; getIndex ( n , shuffle ) ;