changer6360
12/28/2016 - 3:19 PM

Codingame

Codingame

import Glibc

public struct StderrOutputStream: OutputStreamType {
    public mutating func write(string: String) { fputs(string, stderr) }
}
public var errStream = StderrOutputStream()

/**
 * 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.
 **/

let inputs = (readLine()!).characters.split{$0 == " "}.map(String.init)
let lightX = Int(inputs[0])! // the X position of the light of power
let lightY = Int(inputs[1])! // the Y position of the light of power
var initialTX = Int(inputs[2])! // Thor's starting X position
var initialTY = Int(inputs[3])! // Thor's starting Y position
var coordinate = ""

// game loop
while true {
    
    let remainingTurns = Int(readLine()!)! // The remaining amount of turns Thor can move. Do not remove this line.

    // Write an action using print("message...")
    // To debug: debugPrint("Debug messages...", toStream: &errStream)

    if initialTY == lightY {
    
        if initialTX < lightX {
        initialTX += 1
        coordinate = "E"
        } else {
        initialTX -= 1
        coordinate = "W"
        }
        
    } else if (initialTY > lightY) {
    
        if initialTX == lightX {
        initialTY -= 1
        coordinate = "N"
        } else if (initialTX > lightX) {
        coordinate = "NW"
        initialTX -= 1
        initialTY -= 1
        } else {
        coordinate = "NE"
        initialTX += 1
        initialTY -= 1
        }
        
     } else if (initialTY < lightY) {
     
        if initialTX == lightX {
        coordinate = "S"
        initialTY += 1
        } else if (initialTX > lightX) {
        coordinate = "SW"
        initialTX -= 1
        initialTY += 1
        } else {
        coordinate = "SE"
        initialTX += 1
        initialTY += 1
        }
           
      }

    // A single line providing the move to be made: N NE E SE S SW W or NW
    print(coordinate)
}