War - Puzzle Discussion


I’m not sure what’s wrong with your input, but each player has 9 cards in that test case, not 6.
P1 has: 8C, KD, AH, QH, 3D, KD, AH, QH, 6D
P2 has: 8D, 2D, 3H, 4D, 3S, 2D, 3H, 4D, 7H

8C vs. 8D: WAR
8C, KD, AH, QH and 8D, 2D, 3H, 4D go to each “war deck”
Next they draw: 3D, 3S: WAR
3D, KD, AH, QH and 3S, 2D, 3H, 4D go to each “war deck”
Next they draw: 6D, 7H: Player 2 wins and gets everything.

Maybe there is something wrong when you read the input?

Edit: Looks like all cards which go into the war deck are duplicates. Do you possibly have a unique check somewhere?


Wow… Come on !! Thank you Garrincha !!


you are probably dealing the card in the opposite order


Not as useless as you might think !
What was your problem? Because I probably have the same.


I was confused by this game, because I did not return the 3 cards one by one (making things complex for realistic when the algo is simple).
It would have been better with clear examples :wink:


Thanks! I’ve had a problem like that a few years ago… A shame I didn’t remember that. You got me to 100%! :tada:


solved 100%, but too long to debug. The difficulty should be in the problem, not in long data to read and deal with truncated debug info if there are too many rows.

> p1 cards 8C KD AH QH **2S**
> p2 cards 8D 2D 3H 4D **3S**
> 8C vs 8D
> p1Wins

You code should conclude that P2 wins (3>2)


Thank you, you saved me.

I misread the given explanation and added the cards of the winning player first (like it is with most games of that type I know).

I even went through the faulty case by hand and arrived at the same solution (as I added winning player first again).

Stupid head replacing “first player” with “winning player”.

Anyway, thanks. Now I can go to sleep :smiley:


Here is something I have learned. You can play the cards in the reverse order and some test cases will pass. You can put cards from a War into the deck in the wrong order and still pass many of the tests.

So just because many of the tests pass does not mean you are moving cards around in the correct order.