Created
April 3, 2014 03:22
-
-
Save damondouglas/9947761 to your computer and use it in GitHub Desktop.
codingame.com | Question 1 - Power of Thor
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
import 'dart:io'; | |
import 'dart:math'; | |
void main() { | |
String line = stdin.readLineSync(); | |
var e = line.split(' ').map((i) => int.parse(i)).toList(); | |
var lx = e[0]; | |
var ly = e[1]; | |
var tx = e[2]; | |
var ty = e[3]; | |
var dx = lx - tx; | |
var dy = ly - ty; | |
var ns = { | |
-1:"N", | |
0:"", | |
1:"S" | |
}; | |
var ew = { | |
-1:"W", | |
0:"", | |
1:"E" | |
}; | |
var adx = dx.abs(); | |
var ady = dy.abs(); | |
var maxd = max(adx,ady); | |
var mind = min(adx,ady); | |
var diagX = []; | |
var diagY = []; | |
var strtX = []; | |
var strtY = []; | |
diagX.addAll(new List.filled(mind, ew[dx.sign])); | |
diagY.addAll(new List.filled(mind, ns[dy.sign])); | |
dx = dx - mind; | |
dy = dy - mind; | |
strtX.addAll(new List.filled(maxd-mind, ew[dx.sign])); | |
strtY.addAll(new List.filled(maxd-mind, ns[dy.sign])); | |
var moveX = []..addAll(diagX)..addAll(strtX); | |
var moveY = []..addAll(diagY)..addAll(strtY); | |
var move = new List.generate(maxd, (int index) => moveY[index]+moveX[index]); | |
move.forEach((m) => print(m)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment