The other evening when playing bridge, one player was dealt a hand containing 26 points. I then wondered what the probability was and thought: just the job for a simple program.

Background: each bridge player is dealt 13 of the 52 cards. Simple points values are 4 for an Ace, 3 for a King, 2 for a Queen and 1 for a Jack (Knave).

Program: I arbitrarily distribute 4 lots of 4 points, 3 points, 2 points and 1 point through the 52-card pack - the array elements Pack%%(n, 0). Then I randomly select 13 of the 52 cards and add up the points value - variable CardsValue%%. For each points value obtained I calculate the probability of obtaining that value over many deals - elements Probs~&&(CardsValue%%, 0) and also the probability of getting that value or greater Probs~&&(CardsValue%%, 1).

The program I have written gives zero probability for points values 30 and 32 to 37. They should have very small values, but not zero (you could get up to 37: 4 Aces, 4 Kings, 4 Queens and a Jack).

I wonder if you could find out where I have gone wrong. It is strange that I should be able to make such an elementary error - don't tell Fellippe, he'll bar me from the site!

Thanks.

`CONST True = -1`, False = 0``

DIM Probs~&&(40, 1), Pack%%(52, 1)

_TITLE "Points Count Probabilities in Bridge"

'A = 4, K = 3, Q = 2, J = 1

FOR N%% = 1 TO 4

FOR M%% = 0 TO 3

Pack%%(N%% + (13 * M%%), 0) = 5 - N%%

NEXT M%%

NEXT N%%

OPEN "temp.txt" FOR OUTPUT AS #2

'FOR N%% = 1 TO 52

' PRINT #2, Pack%%(N%%, 0)

'NEXT N%%

'END

RANDOMIZE (TIMER)

WHILE INKEY$ = ""

Count~&& = Count~&& + 1

FOR N%% = 1 TO 52

Pack%%(N%%, 1) = False

NEXT N%%

CardsValue%% = 0

FOR N%% = 1 TO 13

Dealt` = True

WHILE Dealt`

Card%% = 1 + INT(52 * RND)

IF NOT Pack%%(Card%%, 1) THEN

Pack%%(Card%%, 1) = True

Dealt` = False

END IF

WEND

CardsValue%% = Pack%%(Card%%, 0) + CardsValue%%

NEXT N%%

Probs~&&(CardsValue%%, 0) = Probs~&&(CardsValue%%, 0) + 1

FOR N%% = 0 TO CardsValue%%

Probs~&&(N%%, 1) = Probs~&&(N%%, 1) + 1

NEXT N%%

IF Count~&& / 100000 = Count~&& \ 100000 THEN

CLS

PRINT Count~&&

FOR N%% = 0 TO 40

P0! = Probs~&&(N%%, 0) / Count~&&

P1! = Probs~&&(N%%, 1) / Count~&&

PRINT N%%; P0!; P1!,

IF N%% \ 2 = N%% / 2 THEN PRINT ""

NEXT N%%

RANDOMIZE (TIMER)

END IF

WEND

PRINT #2, Count~&&

FOR N%% = 0 TO 40

P0! = Probs~&&(N%%, 0) / Count~&&

P1! = Probs~&&(N%%, 1) / Count~&&

PRINT #2, N%%; P0!; P1!

NEXT N%%

CLOSE #2

SYSTEM