Skip to content

Instantly share code, notes, and snippets.

@mnhollandplum
Last active January 28, 2019 17:26
Show Gist options
  • Select an option

  • Save mnhollandplum/269a5eb23c7d7c45448495f20edda333 to your computer and use it in GitHub Desktop.

Select an option

Save mnhollandplum/269a5eb23c7d7c45448495f20edda333 to your computer and use it in GitHub Desktop.
class Robot
def initialize(current_location = [0,0], input)
@current_location = current_location
@input = input
@current_direction = "N"
@direction_options = ["N","W", "S", "E"]
end
def starting_location
[0,0]
end
def returns_to_origin
if @current_location=="" || @current_location == starting_location
true
else
false
end
end
def movements
@input.map do |move|
if move == "G"
move_forward
elsif move == "L"
left_turn
elsif move == "R"
right_turn
else
p "you entered an invalid movement"
end
end
end
def move_forward
if @current_direction == "N"
@current_location[1] +=1
elsif @current_direction == "W"
@current_location[0] -=1
elsif @current_direction == "S"
@current_location[1] -=1
elsif @current_direction == "E"
@current_location[0] += 1
end
def left_turn
end
def right_turn
end
# Would update the current direction based on the current direction and the direction turning. Couldn't quite figure out the approach in time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment