
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Program to find number of ways to arrange n rooks so that they cannot attack each other in Python
Suppose we have a number n representing a chessboard of size n x n. We have to find the number of ways we can place n rooks, such that they cannot attack each other. Here two ways will be considered different if in one of the ways, some cell of the chessboard is occupied, and another way, the cell is not occupied. (We know that rooks can attack each other if they are either on the same row or on the same column).
So, if the input is like 3, then the output will be 6
To solve this, we will follow these steps −
f = factorial of n
return f
Let us see the following implementation to get better understanding −
Example
import math class Solution: def solve(self, n): return math.factorial(n) ob = Solution() print(ob.solve(3))
Input
3
Output
6
- Related Articles
- Program to arrange cards so that they can be revealed in ascending order in Python
- Program to find number of ways we can arrange symbols to get target in Python?
- Program to find number of ways we can arrange letters such that each prefix and suffix have more Bs than As in Python
- Place K-knights such that they do not attack each other in C++
- Number of Ways to Wear Different Hats to Each Other in C++
- Program to find number of ways we can get n R.s using Indian denominations in Python
- Program to find number of ways to split a string in Python
- What is so special about the leaves, that they can synthesize food, but other part of the plant cannot?
- C++ Program to Find number of Ways to Partition a word such that each word is a Palindrome
- Program to count number of ways we can throw n dices in Python
- Program to count the number of ways to distribute n number of candies in k number of bags in Python
- Program to find number of islands, from where we cannot leave in Python
- Program to find number of ways to split array into three subarrays in Python
- Python program to find ways to get n rupees with given coins
- Program to find number m such that it has n number of 0s at end in Python

Advertisements