[Community Puzzle] Blackjack solver

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @CeliTop,validated by @Zeffar,@Ayza and @WooDyDooKs.
If you have any issues, feel free to ping them.

After solving this challenge, I noticed that one case verification seems to be missing. The case when the bank has Blackjack and the player has 21 points but no Blackjack (using more than 2 cards to get to 21 points).

To put it into a written test case:

A Q
K 9 2

Is it possible to add this test case after the creation of the challenge is completed?

Better add it earlier than later, before many players have solved the puzzle and submitted their solutions.

There would appear to be an issue with the practice test cases on this puzzle.
Both 7 and 8 have the same input (21 and 21) however, test 7 expects this to ourput “Blackjack!” but test 8 expects “Draw” - which are we supposed to be outputting?

One is a hand worth 21 and a blackjack (which are different according to the description), the other is two blackjacks.

2 Likes

I should have re-read the statement. Thanks!

I think there is a bug in test 06, the bank got a blackjack but pull another one card.

In PHP:

var_dump($bankCards);
My console return:
string(6) "A J 10 // → the sum is 31

Its impossible to pull again after a blackjack.
So to fix this i put all values in an array and the third elements after “blackjack” take the values 0.
Then i delete the last element with value 0 in the array.

if(($tabBank[0]) == ‘11’ && $tabBank[1] == ‘10’){

$tabBank[2] = '0';

}

if($tabBank[2] == ‘0’){

unset($tabBank[2]);

} // After this, console return " A J " which is a blackjack.

Do the same for the array “player”, hope that will help some people, good luck.

Hi sweedow (and any future others) –

This potential confusion was a concern I had when this puzzle was still in the pending stage, but to address that, the puzzle-creator noted explicitly:
“Entries are not listed in the order the cards were dealt (the order does not matter)”

So the Bank could have drawn 10 and then J and then decided to take another card. And the 3rd card was the A.

I hope this helps clarify

1 Like

in the test my solution it’s correct but when i submit i got error in blackjack Draw , i try all posible solution to get the correct result but nothing… one of the two i have botato skills or there something in the test

Hi,

The validator “Blackjack draw” is similar to the test, both the player and the bank have a backjack, only difference is in the test the ace is the first card, in the validator it’s the second card.

Inputs for the validator

10 A
J A

1 Like

I have problems with “Too much” and “Both too much” validators, any tip?

Please put validator inputs in spoiler tags, thanks. (You can find it under the last button of the formatting toolbar.)

Maybe you’re not handling when a hand is over 21 correctly.
Like…
21 beats 20
But 22 doesn’t beat 21

“So the Bank could have drawn 10 and then J and then decided to take another card. And the 3rd card was the A.”

Just a note that is completely irrelevant to the puzzle as stated. In blackjack, the bank has specific rules about when it will and will not select another card. If the value of the bank’s hand is 16 or less, it has to draw another card. If it has a 17 or higher, it cannot draw another card. So you would never see an instance where a bank would draw a 10 and a J and then decide to draw another card.

Again, not relevant to the puzzle as stated. Just assume that the dealer in this game does not know what he is doing.

EDIT: After re-reading I laughed out loud. The very first sentence is the bank has forgot the rules. Clearly.

The one thing that really bothers me is that if a player gets Blackjack (score of 21 in two cards), it doesn’t matter what cards dealer has as they are not evaluated. Player wins 1.5 times the bet that he placed and game continues.
What I’m saying is that Blackjack draw can never happen. But overall a great puzzle, it was fun, thanks.

I just wanted to say, would it make sense to include a point in the challenge description about the bank winning when both player and bank go bust?

The statement does mention it:

If both exceeds 21, the bank win.

I’m currently confused at what’s occurring with my solution. I’m working in C++ and I added an integer that going to be used to store data and I got the ! saying that the code I’m testing against is out of date because changed the code. So, I run it again and I was working on getting the logic for Aces to work in the case of drawing a card that would knock someone over 21 to change the Aces value to 1. It says I’m failing the 1st test. Mind you the only change I did was add the integer. So, I check the logic for it and come to find out that its now suddenly going through the loop an extra time and this is after commenting all my other code out to find the cause and they way it was fixed was by commenting out the newly made integer. So, I’m really confused and hope someone can help me figure this out.

I figured it out and got it working! Definitely needed to step away and rethink it. :smile:

I dont’ understand why tests 2 and 10 fail in Validator