Number of moves required to guess a permutation . | Function that returns the required moves ; Final move ; Driver code
function countMoves ( n ) { let ct = 0 ; for ( let i = 1 ; i <= n ; i ++ ) ct += i * ( n - i ) ; ct += n ; return ct ; } let n = 3 ; document . write ( countMoves ( n ) ) ;