Created
May 6, 2018 19:56
-
-
Save jtslear/d1be9473cc8ed9c276cf7f3ddff337c0 to your computer and use it in GitHub Desktop.
This file contains 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
package main | |
import "fmt" | |
import "os" | |
/** | |
* 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. | |
**/ | |
type Vertex struct { | |
X int | |
Y int | |
} | |
func main() { | |
// 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 | |
var lightX, lightY, initialTX, initialTY int | |
fmt.Scan(&lightX, &lightY, &initialTX, &initialTY) | |
for { | |
// remainingTurns: The remaining amount of turns Thor can move. Do not remove this line. | |
var remainingTurns int | |
fmt.Scan(&remainingTurns) | |
// fmt.Fprintln(os.Stderr, "Debug messages...") | |
var light, thor Vertex | |
light.X = lightX | |
light.Y = lightY | |
thor.X = initialTX | |
thor.Y = initialTY | |
// A single line providing the move to be made: N NE E SE S SW W or NW | |
var EW, NS string | |
switch { | |
case light.X < thor.X: | |
EW = "W" | |
thor.X-- | |
fmt.Fprintf(os.Stderr, "%d:%d - %s\n", thor.X, light.X, EW) | |
case light.X == thor.X: | |
EW = "" | |
fmt.Fprintf(os.Stderr, "%d:%d - %s\n", thor.X, light.X, EW) | |
case light.X > thor.X: | |
EW = "E" | |
thor.X++ | |
fmt.Fprintf(os.Stderr, "%d:%d - %s\n", thor.X, light.X, EW) | |
} | |
switch { | |
case light.Y < thor.Y: | |
NS = "N" | |
thor.Y-- | |
fmt.Fprintf(os.Stderr, "%d:%d - %s\n", thor.Y, light.Y, NS) | |
case light.Y == thor.Y: | |
NS = "" | |
fmt.Fprintf(os.Stderr, "%d:%d - %s\n", thor.Y, light.Y, NS) | |
case light.Y > thor.Y: | |
NS = "S" | |
thor.Y++ | |
fmt.Fprintf(os.Stderr, "%d:%d - %s\n", thor.Y, light.Y, NS) | |
} | |
chosenDirection := fmt.Sprintf("%s%s", NS, EW) | |
fmt.Fprintf(os.Stderr, "%s\n", chosenDirection) | |
fmt.Println(chosenDirection) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment