I am trying to write a mathematical function for calculating the probability of winning or loosing the player.
Assume that we play blackjack with only one deck(52 cards) and the first example hand is like that :
The player has `7 and 5`
Dealer has `6`
Here I need the calculate if player stands, what is the probibility of dealers win?
The dealer can win if the total cards value are 17 <= x <= 21
I can calculate this with code like this but this is very inefficient for 6 decks.
def subset_sum(numbers, target, target2, partial=[]):
s = sum(partial)
# check if the partial sum is equals to target
if s >= target and s <= target2:
print partial
if s >= target:
return # if we reach the number why bother to continue
for i in range(len(numbers)):
n = numbers[i]
remaining = numbers[i+1:]
subset_sum(remaining, target, target2, partial + [n])
I am searching for a mathematical function which calculates the probability and return it.
def get_prob(deck, small_number, big_number):
return prob
In our example, dealer has 6 so small number will be 17-6=11 and big number is 21-6=15.
5,6,7 are used in first hand so my deck has now like this :
dec = [1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]
With these numbers,
dealer has 6 so small number is 17-6 = 11 and 21-6 = 15
def get_prob(dec,11,15):
return prob
Problem: what is the probability that the sum of the cards will be between 11 and 15 ?