Created
September 22, 2022 01:08
-
-
Save Josephchinedu/bdc48634601b41a4fe452bbd4f34be1c to your computer and use it in GitHub Desktop.
Robot return to origin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Description: | |
Imagine a robot standing at position (0,0) in a 2D grid, given a string consisting of its moves, find the | |
final location of the robot | |
Type of parameters passed | |
U: up, INCREASE in the y-axis | |
D: down, DECREASE in the y axis | |
R: right, INCREASE in the x-axis | |
L: left, DECREASE in the x-axis | |
example: | |
params = UD | |
start_position = (0, 0) | |
We'll represent our current position by 2 variables x and y which will initially be both at zero | |
The first character we encounter is the character 'U', which stands for 'UP'. Will increase the y axis of our position by one | |
(1). | |
Our current postiom = (0, 1) | |
Next, we move to the second character which is "D" which stands for decrementing the y-axis by one(1). | |
our current position will be zero & zero | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment