Last active
November 2, 2015 23:10
-
-
Save erdem/be7d0e3bf65ea1a407d3 to your computer and use it in GitHub Desktop.
CodinGame: Skynet - The Chasm
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
/** | |
* Auto-generated code below aims at helping you parse | |
* the standard input according to the problem statement. | |
**/ | |
var road = parseInt(readline()); // the length of the road before the gap. | |
var gap = parseInt(readline()); // the length of the gap. | |
var platform = parseInt(readline()); // the length of the landing platform. | |
var RoadAndGapLength = road+gap; | |
var maxSpeed = gap + 1; | |
function needJump(speed, coordX){ | |
return (road - speed - coordX) < 0 && coordX < RoadAndGapLength; | |
} | |
function needSlow(speed, coordX){ | |
return coordX >= RoadAndGapLength || speed > maxSpeed | |
} | |
function needSpeed(speed, coordX){ | |
return speed < maxSpeed | |
} | |
function needWait(speed, coordX){ | |
return speed == maxSpeed | |
} | |
// game loop | |
while (true) { | |
var speed = parseInt(readline()); // the motorbike's speed. | |
var coordX = parseInt(readline()); // the position on the road of the motorbike. | |
// Write an action using print() | |
// To debug: printErr('Debug messages...'); | |
switch(true) { | |
case (needJump(speed, coordX)): | |
print('JUMP'); | |
break; | |
case (needSlow(speed, coordX)): | |
print('SLOW'); | |
break; | |
case (needWait(speed, coordX)): | |
print('WAIT'); | |
break; | |
case (needSpeed(speed, coordX)): | |
print("SPEED"); | |
break; | |
} | |
// A single line containing one of 4 keywords: SPEED, SLOW, JUMP, WAIT. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment