Codingame Problems
Codingame Problems
Story
Thor's hammer, Mjllnir, has lost all of its powers... Will you be able to
guide Thor towards the light of power to make the hammer whole again?
Pseudo Code
Solution
// 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.
program Answer;
{$H+}
uses sysutils, classes, math;
// Helper to read a line and split tokens
procedure ParseIn(Inputs: TStrings) ;
var Line : string;
begin
readln(Line);
Inputs.Clear;
Inputs.Delimiter := ' ';
Inputs.DelimitedText := Line;
end;
var
lightX : Int32; // the X position of the light of power
lightY : Int32; // the Y position of the light of power
initialTX : Int32; // Thor's starting X position
initialTY : Int32; // Thor's starting Y position
remainingTurns : Int32;
Inputs: TStringList;
thorX : Int32;
thorY : Int32;
directionX : string;
directionY : string;
begin
Inputs := TStringList.Create;
ParseIn(Inputs);
lightX := StrToInt(Inputs[0]);
lightY := StrToInt(Inputs[1]);
initialTX := StrToInt(Inputs[2]);
initialTY := StrToInt(Inputs[3]);
thorX := initialTX;
thorY := initialTY;
// game loop
while true do
begin
ParseIn(Inputs);
remainingTurns := StrToInt(Inputs[0]);
if thorX = lightX then
directionX := ''
else if thorX < lightX then begin
directionX := 'E';
Inc(thorX)
end else begin
directionX := 'W';
Dec(thorX)
end;
if thorY = lightY then
directionY := ''
else if thorY < lightY then begin
directionY := 'S';
Inc(thorY)
end else begin
directionY := 'N';
Dec(thorY)
end;
writeln(directionY + directionX);
flush(StdErr); flush(output); // DO NOT REMOVE
end;
end.
2) Temperatures
Story
It's freezing cold out there! Will you be able to find the temperature closest
to zero in a set of temperatures readings?
Story
You have been promoted to commander of the Mars Lander mission ! The
goal of the operation is to land an exploration rover on martian ground. Your
superiors at NASA expect very much of you for this mission, and you'll have
to prove that you have what it takes to become a great intersideral
commander. You will have to land the space ship on mars, making sure that
the landing is done smoothly.
Directions