6 kyu

Simple Fun #183: Direction In Grid

147 of 313myjinxin2015

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] integer n

number of rows.

1 <= n <= 1000

  • [input] integer m

number of columns.

1 <= m <= 1000

  • [output] a string

The final direction.

Puzzles

Stats:

CreatedMar 6, 2017
PublishedMar 6, 2017
Warriors Trained781
Total Skips22
Total Code Submissions930
Total Times Completed313
JavaScript Completions131
C# Completions48
Python Completions147
Ruby Completions26
Total Stars24
% of votes with a positive feedback rating94% of 87
Total "Very Satisfied" Votes79
Total "Somewhat Satisfied" Votes6
Total "Not Satisfied" Votes2
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • smile67 Avatar
  • hobovsky Avatar
  • dfhwze Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad