
- 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
Check if any square (with one colored cell) can be divided into two equal parts in Python
Suppose, we are provided with a square that is a size of n. The n sized square is further divided into n2 smaller squares. The smaller squares are of unit size and one of the squares is colored with a unique color.
Now if we cut the bigger square into two equal parts, we have to cut it in such a way so that the cutting line does not have any points in common with that uniquely colored small square. We have to also consider the fact that the newly cut two pieces are mirror images of one another. So, we have to find out if cutting a square like that is possible given the conditions. We have the value of n and the position of the colored square in the bigger square.
So, if the input is like size = 50, colored_row_pos = 25, colored_col_pos = 25, then the output will be "Cutting is not possible."
To solve this, we will follow these steps −
- middle := floor value of size /2
- if (middle is same as colored_row_pos or middle is same as colored_row_pos - 1) and (middle is same as colored_col_pos or middle is same as colored_col_pos - 1) , then
- return False
- otherwise,
- return True
Let us see the following implementation to get better understanding −
Example
def solve(size, colored_row_pos, colored_col_pos) : middle = size // 2 if (middle == colored_row_pos or middle == colored_row_pos - 1) and (middle == colored_col_pos or middle == colored_col_pos - 1) : print("Cutting is not possible") else : print("Cutting is possible") size = 50 colored_row_pos, colored_col_pos = 25, 25 solve(size, colored_row_pos, colored_col_pos)
Input
50, 25, 25
Output
Cutting is not possible
- Related Articles
- Check if an array of 1s and 2s can be divided into 2 parts with equal sum in Python
- Check if a large number can be divided into two or more segments of equal sum in C++
- Find if array can be divided into two subarrays of equal sum in C++
- Can array be divided into n partitions with equal sums in JavaScript
- Check if array can be divided into two sub-arrays such that their absolute difference is Ks in Python
- Check if a line at 45 degree can divide the plane into two equal weight parts in C++
- Check if array can be sorted with one swap in Python
- Check if an array can be divided into pairs whose sum is divisible by k in Python
- Partition Array Into Three Parts With Equal Sum in Python
- Minimum Cuts can be made in the Chessboard such that it is not divided into 2 parts in Python
- Find the sums for which an array can be divided into subarrays of equal sum in Python
- Check if a sorted array can be divided in pairs whose sum is k in Python
- Python Pandas – Check if any specific column of two DataFrames are equal or not
- Ravi divided pizza into 6 equal parts and ate 3 parts from it. What is the fraction ?
- Sherin divided one roti into two equal parts and gave one part or $\frac{1}{2}$ of the roti to her daughter. Find the remaining part of roti with her ?
