War - Puzzle Discussion

You are in fact supposed to add first ALL the cards of the first player (so, for each battle, the card launching the battle, the 3 cards placed face down and finally the card that won or lost the last battle) and ALL the cards of the second player after that, contrary to what Strafe said.

I had a similar problem, and it turned out that I misinterpreted how the cards are added to the deck in the beginning. When I changed it from addFirst to addLast, it worked.

This comment is actually false. When there are chained wars, all the cards of every wars are added at the end of the decisive battle.

Exemple

Player 1 deck 5 K Q J 3 2 4 7 6 A 8
Player 2 deck 5 A J Q 3 6 3 5 7 J 9

Here the first war is at 5, the second one at 3, and the decisive battle is won by player 2 at 6-7.

The resulting decks will be

Player 1 deck A 8
Player 2 deck J 9 {5 K Q J 3 2 4 7 6} {5 A J Q 3 6 3 5 7}

As can be seen, all the cards from the first player are first added, followed by those of the second player at the end of all the wars.

6 Likes

Hello everybody,
after read MrAnderson last reply I was wiling to argue and then I understood what I get wrong and what I think should be clarify in the rules.
I thought that in the war there will be 3 fights with and the winner will take all the cards. Now I understand I made a too fast assumption nevertheless I think it could be worthy to say in the rules that those three cards will be just a reward to the winner of the next battle which decid who win the war. Adding the [quote=“MrAnderson, post:63, topic:2417, full:true”]
A war involves 5 cards; the initial one, 3 cards, and then the deciding battle. The battle happens on the same turn as the war.
[/quote]
will be a good improve to the rules.

Thanks for reading

1 Like

well yeah, PAT killed my enthusiasm too (((((

I’m not understanding this PAT rule. For the 4th test ‘Battle’, I logged out the cards:

8,13,14,12
8,2,3,4

That’s 4 cards each player, a battle requires at least 5 cards: 1 initial card, 3 face down, and another decisive card. With only 4 cards each, it would result in a PAT, because the players have run out of cards before laying their decisive card.

Whatever the actual answer to this is, its probably causing me to fail the rest of the tests.

Your advice very helps me.

Hello,

I’m having an issue with the Long War test case. My program in C++ aborts during a deque::erase() operation with the following error code:

Aborted.

at abort.c. function __GI_abort () on line 89
at malloc.c. function _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) on line 3840

Looking at the values of the iterators passed to the operation at the precise moment of it crashing does not suggest why ::erase() is failing, both iterators deference just fine.

thanks ! I had the same issue too :]

But you do need to give all player 1’s played cards from one continues war, and then all the cards from player 2.
Don’t split them up per fight in a war.

Thanks man! YOU ARE THE BEST!
I was double checking all the logic, all was flawless, first 2 cases worked, others no way! Started to pull my hairs out…
Then, luckily for me, I checked forum.
This is freaking stupid move by them to DEAL CARDS IN OPPOSITE ORDER AND DIDN’T MENTION IT AT ALL IN DESCRIPTION!
People who made this puzzle was freaking stupid… :rage:

2 Likes

No, you just don’t know how to read a statement.

OK, lets check it again… I’m quoting puzzle statements:
First it says:

War is a card game played between two players. Each player gets a variable number of cards of the beginning of the game: that’s the player’s deck. Cards are placed face down ON TOP OF EACH DECK.

Then in the input section:

Input

Line 1: the number N of cards for player one.

N next lines: the cards of player one.

Next line: the number M of cards for player two.

M next lines: the cards of player two.

Here you never mention the fact that input is premade deck, and not just cards as you give them in a card game, as any human with a sense of logic will assume.
So, I recommend you to not shield defects of this puzzle’s description by implying my “reading skills”, and rather edit this puzzle description to eliminate this kind of misunderstandings in the future.
Look, I’m not trying to insult you (had a very bad mood after wasting few hours on the time of 1st post), I’m just trying to help this site get better, that’s all.
Peace.

here it’s what you missed in the statement to know that’s already a premade deck :

For example, if the card distribution is the following:
Player 1 : 10D 9S 8D KH 7D 5H 6S
Player 2 : 10H 7H 5C QC 2C 4H 6D
Then after one game turn, it will be:
Player 1 : 5H 6S 10D 9S 8D KH 7D 10H 7H 5C QC 2C
Player 2 : 4H 6D

so as you can see the card distribution are already in the correct way because the second turn show that a war happended with 10D and 10H

The rest of the statement explain how works the real War game.

1 Like

I saw this example.
However, there is no way to know for sure if this example is premade, or is it shown after (obvious) sorting in the normal card game fashion.
It would be OK this way:

For example, if the card distribution given by the input is the following:
Player 1 : 10D 9S 8D KH 7D 5H 6S
Player 2 : 10H 7H 5C QC 2C 4H 6D
Then after one game turn, it will be:
Player 1 : 5H 6S 10D 9S 8D KH 7D 10H 7H 5C QC 2C
Player 2 : 4H 6D

Alternitevly, would be a good idea to remove/change misleading statement at the start of pazzle:

War is a card game played between two players. Each player gets a variable number of cards of the beginning of the game: that’s the player’s deck. Cards are placed face down on top of each deck. However, input will provide premade decks for you.

Something like this.

Im getting 50 turns on test three when it should be 56. Any idea what my problem is?

Very ambiguously worded puzzle.
You spend more time trying to figure out the rules (by reverse engineering from the expected test case results) than solving the problem !

Some tips…

  • 1 battle = one round
  • the round number does not get incremented during chained wars
  • “the 2 changed battles” testcase is badly named - it’s actually 2 chained wars within one battle (= 1 round)

Hi,

I failed the 2 PAT cases. It turns out, if a player runs out of cards for war (the extra 3 cards) it is a PAT.

I did not understand this from the rules, so if you fail at that tests, try it out.

This case is explained in the rules under the heading Special Cases.

Do you really believe this line clearly explains the case:

If a player runs out of cards during a “war” (when giving up the three cards or when doing the battle), then the game ends and both players are placed equally first.

I know there is another line, at output section:

If players are equally first: PAT

but they are seperated, so it is hard to understand.

Also, “players are placed equally first” is a terrible way of saying “game should be considered a draw”