
- 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 it is possible to move from (0, 0) to (x, y) in N steps in Python
Suppose we have a coordinate point (x, y) and another value n. We have to check whether we can move from (0, 0) to (x, y) using n steps or not. We can move any of the four directions left, right, up and down.
So, if the input is like p = (2, 1) n = 3, then the output will be True we can move two step to the right then one step to the up direction.
To solve this, we will follow these steps −
- if n >= |x of p| + |y of p| and (n -(|x of p| + |y of p|)) is even, then
- return True
- return False
Example
Let us see the following implementation to get better understanding −
def solve(p, n): if n >= abs(p[0]) + abs(p[1]) and (n - (abs(p[0]) + abs(p[1]))) % 2 == 0: return True return False p = (2, 1) n = 3 print(solve(p, n))
Input
(2, 1), 3
Output
True
- Related Articles
- Check if it is possible to create a palindrome string from given N in Python
- Check if it is possible to create a polygon with given n sidess in Python
- Check if possible to move from given coordinate to desired coordinate in C++
- Check if it is possible to survive on Island in Python
- Check if it is possible to transform one string to another in Python
- Check if it is possible to sort the array after rotating it in Python
- Maximum steps to transform 0 to X with bitwise AND in C++
- Check if it is possible to form string B from A under the given constraint in Python
- Find the values of $x, y$ if the distances of the point $(x, y)$ from $(-3, 0)$ as well as from $(3, 0)$ are 4.
- Check if it is possible to serve customer queue with different notes in Python
- Python Program to Check if a Number is Positive, Negative or 0
- From the choices given below, choose the equation whose graph is given in figure.$y = x$$x + y = 0$$y = 2x$$2 + 3y = 7x$"\n
- Check if Array is Free From 0 and Negative Number in Java
- Check if it is possible to create a polygon with a given angle in Python
- If points $( a,\ 0),\ ( 0,\ b)$ and $( x,\ y)$ are collinear, prove that $\frac{x}{a}+\frac{y}{b}=1$.

Advertisements