Simple Fun #183: Direction In Grid
Description:
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.
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]
integern
number of rows.
1 <= n <= 1000
[input]
integerm
number of columns.
1 <= m <= 1000
[output]
a string
The final direction.
Similar Kata:
Stats:
Created | Mar 6, 2017 |
Published | Mar 6, 2017 |
Warriors Trained | 781 |
Total Skips | 22 |
Total Code Submissions | 930 |
Total Times Completed | 313 |
JavaScript Completions | 131 |
C# Completions | 48 |
Python Completions | 147 |
Ruby Completions | 26 |
Total Stars | 24 |
% of votes with a positive feedback rating | 94% of 87 |
Total "Very Satisfied" Votes | 79 |
Total "Somewhat Satisfied" Votes | 6 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 6 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |