War - troubleshooting

Back to Topic List

aszaloki     2025-10-08 14:32:35

Hi Kevin,

I have implemented this problem and got the same answer as the shortened (both players with 14 cards) example with the table of turns. But for the example with the 3 cases I've got the answer: 1 442 2 25 1 1068 (instead of 2 600 1 191 2 4770).

I have checked my shuffling algorithm based on the description and it seems to be correct. The initial deck is also checked, it is: 2H,3H,4H,...KH,AH,2D,3D,4D,...KD,AD,2C,3C,4C,...KC,AC,2S,3S,4S,...KS,AS

Then the cards are dealt to each player one-at-a-time, starting with Player 1, as stated in the description

So I'm a little bit puzzled, what could I missed?

Could you please take a look at my code (I think it is not complicated at all), or give any hint where my bug may be hiding? If you need some further details from my solution, feel free to ask for it :)

Many thanks!

admin (Kevin)     2025-10-09 02:14:15
User avatar

Hi Adam!

Your code looks great! Turns out there was a small error in my own code, which due to the deterministic nature of the problem completely threw off the answers. The examples do now yield the numbers you gave above, so I imagine your code should work for you now.

aszaloki     2025-10-09 08:04:54

Hi Kevin,

thank you so much, now everything is working.

Please login and solve 5 problems to be able to post at forum