12
Blackjack, also known as twenty-one, is a comparing card game between yourself and a dealer, where each player in turn competes against the dealer, but players do not play against each other.
Play goes as follows, the dealer deals you a card. The dealer then deals them-self a card, face down. The dealer then deals you another card. Then finally, the dealer deals them-self a card, face-up.
Challenge
Your challenge is to write a program (or function) that when run (or called), outputs (or returns) the probability that the next card the dealer gives you will make you bust, which means the cumulative score of cards in your hand after the dealer gives you another card is over 21.
Input
The three visible cards in play. They are the two cards you have in your hand, and the one face card you can see in the dealers hand. This can be in whatever format you find suitable for your application.
There are 52 cards in a deck(4 of each of the cards below). The value of the cards are as follows:
Symbol(Case Insensitive) Name Value
2 Two 2
3 Three 3
4 Four 4
5 Five 5
6 Six 6
7 Seven 7
8 Eight 8
9 Nine 9
T Ten 10
J Jack 10
Q Queen 10
K King 10
A or 1 Ace 1
In Blackjack, an ace can count as 1 or 11. In our challenge, only count it as a 1
Output
The probability, in a ratio or percentage format, that the next card we draw will make us bust.
You may output the percentage, the fraction, or just the numerator of the fraction.
Examples
In this example, the first two cards are in our hand, the third card is the dealers visible card
Input -> Output
A 2 Q -> 0.00% or 0/49 or 0
A 2 3 -> 0.00% or 0/49 or 0
T T T -> 91.84% or 45/49 or 91.84
T J K -> 91.84% or 45/49 or 45
9 7 3 -> 61.22% or 30/49 ...
9 7 Q -> 59.18% or 29/49 ...
Rules
Standard loopholes are not allowed.
This is code-golf, so the shortest code in bytes for each language wins!
2Are we allowed to take the ace as 1 and face cards as 10s, or would that be stretching the input format too far? – None – 2018-05-07T15:52:29.870
So, we can take face cards as 10? – wastl – 2018-05-07T15:54:23.110
@Mnemonic Taking the Ace as
1
is fine. – DevelopingDeveloper – 2018-05-07T15:55:42.657@Mnemonic @wastl The inputs are only one character, so I am going to have to say no. Take them as
QJKT
. – DevelopingDeveloper – 2018-05-07T15:56:09.437Can I take them as lowercase letters? – None – 2018-05-07T15:56:34.047
@Mnemonic Yes that is fine. – DevelopingDeveloper – 2018-05-07T15:57:02.673
1@Arnauld Thank you for the catch. I updated the ratios but not the probabilities. As for your output question yest that is fine. You do not have to add the /49 on each answer. – DevelopingDeveloper – 2018-05-07T18:03:27.483
1"T J K -> 91.84% or 45/49 or 45 or etc..." - so we may simply output the numerator? If so could you state it in the text? – Jonathan Allan – 2018-05-07T18:37:16.030
1@JonathanAllan Updated – DevelopingDeveloper – 2018-05-07T19:47:40.970