Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 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.
- -- lightX: the X position of the light of power
- -- lightY: the Y position of the light of power
- -- initialTX: Thor's starting X position
- -- initialTY: Thor's starting Y position
- next_token = string.gmatch(io.read(), "[^%s]+")
- lightX = tonumber(next_token())
- lightY = tonumber(next_token())
- thorX = tonumber(next_token())
- thorY = tonumber(next_token())
- moves = {
- [-1] = {[-1]='NW', [0]='N', [1]='NE'},
- [0] = {[-1]='W', [0]='x', [1]='E'},
- [1] = {[-1]='SW', [0]='S', [1]='SE'}
- }
- -- game loop
- while true do
- remainingTurns = tonumber(io.read()) -- The remaining amount of turns Thor can move. Do not remove this line.
- -- Write an action using print()
- -- To debug: io.stderr:write("Debug message\n")
- dx = lightX - thorX
- dy = lightY - thorY
- if dx ~= 0 then dx = dx / math.abs(dx) end
- if dy ~= 0 then dy = dy / math.abs(dy) end
- thorX = thorX + dx
- thorY = thorY + dy
- -- A single line providing the move to be made: N NE E SE S SW W or NW
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement