# Task
 You're standing at the top left corner of an `n × m` grid and facing towards the `right`. 
 
 Then you start walking one square at a time in the direction you are facing. 
 
 If you reach the border of the grid or if the next square you are about to visit has already been visited, you turn right. 
 
 You stop when all the squares in the grid are visited. What direction will you be facing when you stop?

 You can see the example of your long walk in the image below. The numbers denote the order in which you visit the cells.

 ![](https://i.gyazo.com/2fc5884d2c227a0ddeca503e6a0261be.png)

 Given two integers n and m, denoting the number of rows and columns respectively, find out the direction you will be facing at the end. 
 
 Output `"L"` for left, `"R"` for right, `"U"` for up, and `"D"` for down.

# Example:

 For `n = 3, m = 3`, the output should be `"R"`.

 This example refers to the picture given in the description. At the end of your walk you will be standing in the middle of the grid facing right.

# Input/Output


 - `[input]` integer `n`
 
 number of rows.

 `1 <= n <= 1000`


 - `[input]` integer `m`
 
 number of columns.

 `1 <= m <= 1000`
 
 
 - `[output]` a string

 The final direction.

Source: codewars | Difficulty: EASY
Tags: Ad-hoc

Starter code: def direction_in_grid(n,m):
	

Solutions:
def direction_in_grid(n, m):
	return 'LR'[n % 2] if m >= n else 'UD'[m % 2]


def direction_in_grid(n, m):
	return 'LRUD'[n % 2 if m >= n else 2 + m % 2]


NEXT = {'R': 'D', 'D': 'L', 'L': 'U', 'U': 'R'}

def direction_in_grid(n, m, d='R'):
	while n > 1:
		(n, m, d) = (m, n - 1, NEXT[d])
	return d


direction_in_grid = lambda n, m: 'LRUD'[min(n, m) % 2 + 2 * (m < n)]


direction_in_grid = lambda n, m: ['LR'[n % 2], 'UD'[m % 2]][n > m]


def direction_in_grid(n, m):
	index = 0
	directionByIndex = {0: 'U', 1: 'R', 2: 'D', 3: 'L'}
	if n <= m:
		index = (n * 2 - 1) % 4
	else:
		index = m * 2 % 4
	return directionByIndex.get(index)


def direction_in_grid(n, m):
	if m > n:
		return 'L' if n % 2 == 0 else 'R'
	elif m < n:
		return 'U' if m % 2 == 0 else 'D'
	else:
		return 'L' if n % 2 == 0 else 'R'