Skip to content

Instantly share code, notes, and snippets.

@eric-taix
Created February 21, 2015 17:03
Show Gist options
  • Save eric-taix/e97600883a71140c6985 to your computer and use it in GitHub Desktop.
Save eric-taix/e97600883a71140c6985 to your computer and use it in GitHub Desktop.
gc-power-of-thor
import 'dart:io';
import 'dart:math';
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
Point lightOfPowerPoint;
Point thorPoint;
void main() {
List<int> line = stdin.readLineSync().split(' ').map((s) => int.parse(s)).toList();
lightOfPowerPoint = new Point(line[0], line[1]);
thorPoint = new Point(line[2], line[3]);
while (true) {
int E = int.parse(stdin.readLineSync());
String move = chooseMoveY();
move += chooseMoveX();
print(move);
}
}
String chooseMoveY() {
if (thorPoint.y < lightOfPowerPoint.y) {
thorPoint = new Point(thorPoint.x, thorPoint.y + 1);
return 'S';
} else if (thorPoint.y > lightOfPowerPoint.y) {
thorPoint = new Point(thorPoint.x, thorPoint.y - 1);
return 'N';
}
return '';
}
String chooseMoveX() {
if (thorPoint.x < lightOfPowerPoint.x) {
thorPoint = new Point(thorPoint.x + 1, thorPoint.y);
return 'E';
} else if (thorPoint.x > lightOfPowerPoint.x) {
thorPoint = new Point(thorPoint.x - 1, thorPoint.y);
return 'W';
}
return '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment