You start with a standard deck of cards. Each card is assigned a numeric value from 1 to 52 as follows:
A through K of Clubs = 1 through 13
A through K of Diamonds = 14 through 26
A through K of Spades = 27 through 39
A through K of Hearts = 40 through 52
Each player draws two cards and calculates the cube of the sum of the values of the two cards. Each player then selects five or less nonzero digits from their answer to form their Poker hand. Hands are evaluated solely on the digits, 1 is low and 9 is high, and there are no suits involved. For example: One player draws the 4 of Clubs (4) and the 6 of Diamonds (19); 4 + 19 = 23, 23^3 = 12167, the player has a pair of 1's. A second player draws the Ace of Dimaonds (14) and the Ace of Clubs (1); 14 + 1 = 15, 15^3 = 3375 and she wins the hand with a pair of 3's.
Given these rules, what is the best possible Poker hand a player can have and how many possible combinations of cards will yield that hand?
The version of the program below seeks full houses, after previous versions unsuccessfully looked for 5 or 4 of a kind. The current version finds that a physical hand with a total of 92 will produce the cube 778688, and therefore a full house of 88877, the best that can be done.
The program also checks for 4straights, having unsuccessfully looked for regular straights of 5 cards, just to check that its straight finding mechanism is working properly.
CLS
FOR s = 3 TO 103
t = s * s * s
h$ = LTRIM$(STR$(t))
DO
ix = INSTR(h$, "0")
IF ix = 0 THEN EXIT DO
h$ = LEFT$(h$, ix  1) + MID$(h$, ix + 1)
LOOP
'look for full house
FOR d = 1 TO 9
dig$ = MID$("198765432", d, 1)
ct = 0
psn = 0
DO
ix = INSTR(psn + 1, h$, dig$)
IF ix THEN ct = ct + 1: ELSE EXIT DO
psn = ix
LOOP
IF ct >= 3 THEN
pdig$ = dig$
FOR d2 = 1 TO 9
dig$ = MID$("198765432", d2, 1)
IF dig$ <> pdig$ THEN
ct = 0
psn = 0
DO
ix = INSTR(psn + 1, h$, dig$)
IF ix THEN ct = ct + 1: ELSE EXIT DO
psn = ix
LOOP
IF ct >= 2 THEN
PRINT s, t, h$
END IF
END IF
NEXT
END IF
NEXT
'just for curiosity, check for straights (4straights to be exact)
h2$ = h$
DO
ix = INSTR(h2$, "1")
IF ix = 0 THEN EXIT DO
h2$ = LEFT$(h2$, ix  1) + "A" + MID$(h2$, ix + 1)
LOOP
IF LEN(h$) >= 4 THEN
DO
done = 1
FOR i = 1 TO LEN(h2$)  1
IF MID$(h2$, i, 1) > MID$(h2$, i + 1, 1) THEN
hold$ = MID$(h2$, i, 1)
MID$(h2$, i, 1) = MID$(h2$, i + 1, 1)
MID$(h2$, i + 1, 1) = hold$
done = 0
END IF
NEXT
LOOP UNTIL done
ct = 1
FOR i = 2 TO LEN(h2$)
a = VAL(MID$(h2$, i  1, 1)): b = VAL(MID$(h2$, i, 1))
SELECT CASE b  a
CASE 0
CASE 1
ct = ct + 1
CASE ELSE
ct = 1
END SELECT
IF ct = 4 THEN EXIT FOR
NEXT
IF ct >= 4 THEN
PRINT s, t, h$, "S"
END IF
END IF
NEXT
The results:
54 157464 157464 S
65 274625 274625 S
66 287496 287496 S
76 438976 438976 S
77 456533 456533 S
92 778688 778688
Those marked with S are just the 4straights, and don't count. The answer is the last line, the full house 88877.

Posted by Charlie
on 20090811 17:54:45 