Skynet - The Virus "mood " Bug in Java

Hi, everyone!

I am trying to achieve the ambush points but there is a bug impossible to solve for me. When i set the debug err messages i realize the program doesn’t act as the code dictates, as the program dont have “the mood”.

In example:

I have like this, and for THE SAME IMPUT…

if(…)
{
Sometimes here,…
}
else
{
Sometimes here…
for(int i=0;i<2;i++)
{
when it has the “mood” for go into the for, it does one loop, not 2.
}
}

I hope somebody can have the solution. Thaks to all

That’s not possible. Even when you use (pseudo) random numbers you always get the same output for a given input. That’s how computers work.

Either the input isn’t really the same, or you are relying upon unspecified behaviour somewhere in your code.

Take a look at this page.

Thanks for your reply chrm, but i know enough about of programming for be sure that you are right in that: “Is not possible”,

Then, why i am posting this question? Because i launch THE SAME test, without change nothing in my code, and it make the output as i explain before. It will not be the last time there are bugs on programs here, i am asking how to chat or explain it to the CodinGame developers, because is crazy.

Hey @PabloGonzalezOlmos,

out and err (from System.*.println where * is either out or err), are two differents stream, those two are not sync and they both write in the console.
Because of this behavior, in certain case err will flush its data multiple times before out do it, and you will see multiple lines from err and then one from out and vice versa.

That is what is happening in your program. If you take a look to err messages / out messages separately, they always are the same when you execute your code.
When there is enough CPU computation between two err / out lines, you will see them in the correct order. That’s is what often happens.

You can test this behavior in an IDE with the following:

System.err.println('Hello');
System.out.println('World');
System.err.println('Hello');
System.out.println('World');
System.err.println('Hello');
System.out.println('World');
System.err.println('Hello');
System.out.println('World');
for(int i = 0; i < 10000; ++i) {}
System.err.println('Hello');
for(int i = 0; i < 10000; ++i) {}
System.out.println('World');
for(int i = 0; i < 10000; ++i) {}
System.err.println('Hello');
for(int i = 0; i < 10000; ++i) {}
System.out.println('World');
for(int i = 0; i < 10000; ++i) {}
System.err.println('Hello');
for(int i = 0; i < 10000; ++i) {}
System.out.println('World');

The first messages will have a random order, but when i is time for the for loops, the order should always be the same (or modify i < 10000 for i < 100000 or something greater :slight_smile: )

Thanks again por your reply also, @yohannjardin, i will look later on my code in order to see my err and out println. The one thing i still dont understand is why comes out a err from the else part, a err from the for, but it prints the out from de if. I can understand why the errs and outs are not in order, but not why it writes the err for one section and prints the output for other. See you tomorrow. Good night everyone!!

If I launch your code on the third test, I read:
Round 1 ->

Standard error stream:
????2
????2

Standard output stream:
11 6

Round 2 ->

Standard error stream:
????2
????
VENGAAAAAAAAAAAAAAA
VENGAAAAAAAAAAAAAAA

Standard output stream:
11 5

After this round, the test fail.

If err and out streams were sync, you would read:

Round 1 ->

Standard error stream:
????2
    
Standard output stream:
11 6

Round 2 ->

Standard error stream:
????2
    
Standard output stream:
11 5

Actually, round 1 your code enter the then part of your if, and write “???2” in the standard error output and “11 6” in the standard output.
Then, round 2 you stay in the then part of your if to write a second time “???2” in the standard error output and “11 5” in the standard output.

After that you program continue to run, writing “???2” in the standard error output and something in the standard output.

You then get off of the if. The while loop start again, you finally read the standard inputs given for the round 2 (yes, this round is already finished, but you didn’t read the input so it is still waiting to be read).
This time you enter the else part of your if, and you write “???”, “VENGAAAAAAAAAAAAAAA” and “VENGAAAAAAAAAAAAAAA” on the standard error output.

@yohannjardin, it is solved. Thanks for your patience. I will explain my mistake for someone who had the same missunderstand.

It is all about the printstream, i see the answer to round 2 must be 0-5, but it printed 11-7 ( which is a logical output if the agent was not at the central node, and this output came from de “if” clause, while the 0-5 must come from the “else” clause).

My bug was: How can the program pass through the else and then print some from the if?

The problem was, as i said, the printstream. The if clause, in the first round, made a loop searching for nodes, found 3, and print the 3 ones!! ( i have think once the first println is out ignore the rest…noob of mee :stuck_out_tongue: )… Then, as the program only catch one per round, the two others came later, in queue. This is why the second round didn’t print the “else” result, because it has to print before the second println for the first round.

Then, break, and solved.

Thanks again all!