Hey
I can’t pass the first validation test.
Either the clone got destroy either it is blocked on the generator so no other clone can spawn … i don’t get it …
Can someone explain me ?
Edit :
ok, nevermind the problem was this rule :
If there is no leading clone, the line values are: -1 -1 NONE. This can happen only when the clones which are already outside are all blocked and the next clone is not out yet. In this case, you may output action WAIT.
I’m using Python3 and having the same issue. There is something that i’m not understanding about how to reference the relevant elevator_pos value. I tried this for getting the direction but it gave an error:
if clone_pos < elevator_pos[elevator_floor.index(clone_floor)]:
elevatorDir = ‘RIGHT’
else:
elevatorDir = ‘LEFT’
Hello, I always have an error with the “U Turn” test after submitting my response. The error is “Timeout: the program did not provide 1 input lines in due time…”, but I’ve already added a output “WAIT” when the only head is blocked. Can someone help? Thanks
Anyone an idea what caused it/ how to fix it? Didn’t change anything from the input lines.
Standard Error Stream:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor on line 864
at java.util.Scanner.next on line 1485
at java.util.Scanner.nextInt on line 2117
at java.util.Scanner.nextInt on line 2076
at Player.main on line 32'
for (int i = 0; i < nbElevators; i++) {
int elevatorFloor = in.nextInt(); // floor on which this elevator is found
int elevatorPos = in.nextInt(); // position of the elevator on its floor
}
Why at one point the list can be read and another moment not?
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
class Player
{
static void Main(string[] args)
{
List<int> integerList = new List<int>();
string valeur = "";
string[] inputs;
inputs = Console.ReadLine().Split(' ');
int nbFloors = int.Parse(inputs[0]); // number of floors
int width = int.Parse(inputs[1]); // width of the area
int nbRounds = int.Parse(inputs[2]); // maximum number of rounds
int exitFloor = int.Parse(inputs[3]); // floor on which the exit is found
int exitPos = int.Parse(inputs[4]); // position of the exit on its floor
int nbTotalClones = int.Parse(inputs[5]); // number of generated clones
int nbAdditionalElevators = int.Parse(inputs[6]); // ignore (always zero)
int nbElevators = int.Parse(inputs[7]); // number of elevators
for (int i = 0; i < nbElevators; i++)
{
inputs = Console.ReadLine().Split(' ');
int elevatorFloor = int.Parse(inputs[0]); // floor on which this elevator is found
int elevatorPos = int.Parse(inputs[1]); // position of the elevator on its floor
integerList.Add(elevatorPos);
}
// game loop
while (true)
{
inputs = Console.ReadLine().Split(' ');
int cloneFloor = int.Parse(inputs[0]); // floor of the leading clone
int clonePos = int.Parse(inputs[1]); // position of the leading clone on its floor
string direction = inputs[2]; // direction of the leading clone: LEFT or RIGHT
// Write an action using Console.WriteLine()
// To debug: Console.Error.WriteLine("Debug messages...");
if(cloneFloor == exitFloor)
{
if( ( exitPos < clonePos && direction == "RIGHT" ) || ( exitPos > clonePos && direction == "LEFT" ) )
{
valeur = "BLOCK";
}
else
{
valeur = "WAIT";
}
}
else
{
if( ( integerList[cloneFloor] < clonePos && direction == "RIGHT" ) || ( integerList[cloneFloor] > clonePos && direction == "LEFT" ) )
{
valeur = "BLOCK";
}
else
{
valeur = "WAIT";
}
}
Console.WriteLine(valeur); // action: WAIT or BLOCK
}
}
}
Hi,
I was able to succesfully solve this puzzle in JavaScript but I have a problem while coding the solution in Java. Somehow, the direction is never equal to “RIGHT”. I don’t believe I erased any inital code.
I included below my code and the debug printout for the first level. Does anyone have an idea what I might have done wrong?
Hello Friends!
Would you please tell me what went wrong in my code? It work only for some cases but not for other cases. I am suspecting that the input is wrong.
Auto-generated code below aims at helping you parse
the standard input according to the problem statement.
**/
class Player {
static String what_to_do(String direction, int position, int goal){
return ( ((direction.equals(“LEFT”)) && (position < goal)) || ((direction.equals(“RIGHT”)) && (position > goal)) ) ? “BLOCK” : “WAIT”;
// Block if the direction is opposite from the goal and wait otherwise
}
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int nbFloors = in.nextInt(); // number of floors
int width = in.nextInt(); // width of the area
int nbRounds = in.nextInt(); // maximum number of rounds
int exitFloor = in.nextInt(); // floor on which the exit is found
int exitPos = in.nextInt(); // position of the exit on its floor
int nbTotalClones = in.nextInt(); // number of generated clones
int nbAdditionalElevators = in.nextInt(); // ignore (always zero)
int nbElevators = in.nextInt(); // number of elevators
int[] elevatorFloor = new int[nbElevators];
int[] elevatorPos = new int[nbElevators];
int where_to_go = 0;
int cloneFloor = 0;
int clonePos = 0;
for (int i = 0; i < nbElevators; i++) {
elevatorFloor[i] = in.nextInt(); // floor on which this elevator is found
elevatorPos[i] = in.nextInt(); // position of the elevator on its floor
}
// game loop
while (true) {
cloneFloor = in.nextInt(); // floor of the leading clone
clonePos = in.nextInt(); // position of the leading clone on its floor
String direction = in.next(); // direction of the leading clone: LEFT or RIGHT
try{
where_to_go = (cloneFloor == nbElevators) ? (int) exitPos : (int) elevatorPos[cloneFloor] ;
// just because something went wrong
}catch (Exception e) {
where_to_go = (int) exitPos ;
}
// Write an action using System.out.println()
// To debug: System.err.println("Debug messages...");
System.out.println( what_to_do(direction, clonePos, where_to_go) ); // action: WAIT or BLOCK
}