War (puzzle) - discussion (old thread)

in winamax challange test “26 cards, medium length” out.txt saying that right answer is 2 56, my algo giving output 34, so i simulated this test manually and also get 34 turns( there is no any wars ).
So, am i missing somthing in the game rules or this test is just wrong?


Are you sure you retrieve the data in good order?
There were already some sucessfull submission, so even if it’s not sure at 100 per cent, there are big chances that your code is wrong.
Have you seen if your code procuce the same result for one step on example given just before input format precision?

i manually played that test so its not about code( copied data and started switching bettewn players in notepad :o ). so or test is wrong or my understanding of game rules

EDIT: ok, my mistake i was placing always first card of winner not first player : )


I know it’s been a while since your question but just for information i had an issue too yesterday on the same test
I solved it, the problem was indead in my code, i was not putting the card won by a player in the good order (cards of players1 are always put at the bottom of the turn’s winner deck first)

Hope it helps …



Je réussis tous les tests avec deux méthodes différentes pour le programme, pourtant à chaque fois la validation échoue au Validator 3.
Peut-on savoir ce qu’il a de particulier ?
Peut-on avoir un indice pour réussir la validation de cet item ?


Same problem here: all IDE tests are OK in a very reasonable time (8 ms for the more complex or large cases), but validator #3 keeps failing.

I can only suppose I’m hitting a weird corner case that is not present in the IDE tests but it’s rather hard to figure out what it could be from static analysis alone. Would it be possible to add a variation of this validator as an extra IDE test?

Stumped on it; finally solved it. Here’s the code change that made the difference.


for (uint16_t i = 0; i < height; i++) {
    fgets(&grid[width * i], width + 1, stdin);
    getc(stdin); // must be \n


for (uint16_t i = 0; i < height; i++) {
    fgets(&grid[width * i], width + 1, stdin);
    while (getc(stdin) != '\n');

Likely cause: one of (or many or all?) the lines in the input grid is not width characters wide: it’s more, and the trailing garbage is not whitespace.

Workaround: trim. Ugh.

Solution: CG staff, please fix this.


Thanks you. Problem solved !: slight_smile:

Indeed, read width chars + ignore rest of line instead of read one string… and get 100%.

/flip, that’s all I have to say.

It’s going to be fixed by @_CG_jupoulton
thank you for reporting the issue (and finding the cause)