Ways to place 4 items in n ^ 2 positions such that no row / column contains more than one | Function to return the number of ways to place 4 items in n ^ 2 positions ; Driver code
function NumberofWays ( n ) { var x = ( 1 * n * ( n - 1 ) * ( n - 2 ) * ( n - 3 ) ) / ( 4 * 3 * 2 * 1 ) ; var y = 1 * n * ( n - 1 ) * ( n - 2 ) * ( n - 3 ) ; return 1 * x * y ; } var n = 4 ; document . write ( NumberofWays ( n ) ) ;