Created
April 22, 2016 03:46
-
-
Save dukeimg/e9da8e60eb366620f03d49b9c217e6b8 to your computer and use it in GitHub Desktop.
Power of Thor
This file contains hidden or 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
STDOUT.sync = true # DO NOT REMOVE | |
# Auto-generated code below aims at helping you parse | |
# the standard input according to the problem statement. | |
# --- | |
# Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders. | |
# light_x: the X position of the light of power | |
# light_y: the Y position of the light of power | |
# initial_tx: Thor's starting X position | |
# initial_ty: Thor's starting Y position | |
@light_x, @light_y, @initial_tx, @initial_ty = gets.split(" ").collect {|x| x.to_i} | |
thor_x = @initial_tx | |
thor_y = @initial_ty | |
# game loop | |
loop do | |
remaining_turns = gets.to_i # The remaining amount of turns Thor can move. Do not remove this line. | |
# Write an action using puts | |
# To debug: STDERR.puts "Debug messages..." | |
STDERR.puts @light_y, thor_y | |
direction = '' | |
if thor_y > @light_y | |
direction += 'N' | |
thor_y -= 1 | |
elsif thor_y < @light_y | |
direction += "S" | |
thor_y += 1 | |
end | |
if thor_x > @light_x | |
direction += "W" | |
thor_x -= 1 | |
elsif thor_x < @light_x | |
direction += "E" | |
thor_x += 1 | |
end | |
# A single line providing the move to be made: N NE E SE S SW W or NW | |
puts direction | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment