Skip to content

Instantly share code, notes, and snippets.

@briankung
Last active August 29, 2015 14:05
Show Gist options
  • Save briankung/1253d7bb9fa19140c1a5 to your computer and use it in GitHub Desktop.
Save briankung/1253d7bb9fa19140c1a5 to your computer and use it in GitHub Desktop.
Objects!
filename = "test_cases.txt"
instructions = InstructionReader.new(filename)
# Returns the number of instructions, or how many rovers are given directions
instructions.count
#=> 2
instructions[0].initial_coordinates
#=> [1,2]
instructions[0].initial_direction
#=> "N"
instructions[0].commands
#=> "LMLMLMLMM"
rover = Rover.new(instructions[0])
rover.initial_coordinates
#=> [1,2]
rover.initial_direction
#=> "N"
rover.final_coordinates
#=> [1,3]
rover.final_direction
#=> "N"
# And the same for the next rover.
class Rover
def initialize(instructions)
@instructions = instructions
@commands = @instructions.commands.split('') #=> ['M','L','M','M']
end
def initial_coordinates
@instructions.initial_coordinates
end
def parse_command
command = @commands.shift #=> 'M'
if command == # Do some shit here...
# Do some more shit here
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment