2 4 5 8 9
S D H C H
based on program output
2 4 5 8 9 2 8 5 9 14 14
with the 2 and 8 indicating those as the black cards, and 5 and 9 as being hearts. The odd and even cards each add up to 14.
DECLARE SUB choose (p!)
DIM SHARED card(5), tot, oddTot, evenTot
CLS
choose 1
SUB choose (p)
IF p = 1 THEN st = 1 ELSE st = card(p - 1) + 1
IF p >= 3 THEN IF card(p - 1) - card(p - 2) = 1 THEN st = st + 1
FOR fv = st TO p + 5
card(p) = fv
tot = tot + fv
IF fv MOD 2 = 1 THEN oddTot = oddTot + fv: ELSE evenTot = evenTot + fv
IF p = 5 THEN
IF tot > 24 THEN
FOR c1 = 1 TO 4
FOR c2 = c1 + 1 TO 5
IF c1 > 1 THEN cv1 = card(c1): ELSE cv1 = 0
tot10 = card(1) + cv1 + card(c2)
IF tot10 = 10 THEN
FOR h1 = 0 TO 4
IF h1 <> 1 AND h1 <> c1 AND h1 <> c2 THEN
FOR h2 = h1 + 1 TO 5
IF h2 <> 1 AND h2 <> c1 AND h2 <> c2 THEN
hearts = card(h1) + card(h2)
IF hearts = 14 AND oddTot = evenTot THEN
FOR i = 1 TO 5
PRINT card(i);
NEXT
PRINT , card(c1); card(c2); card(h1); card(h2), oddTot; evenTot
didIt = 1
END IF
END IF
NEXT
END IF
NEXT
END IF
NEXT c2
NEXT c1
END IF
ELSE
choose p + 1
END IF
tot = tot - fv
IF fv MOD 2 = 1 THEN oddTot = oddTot - fv: ELSE evenTot = evenTot - fv
NEXT fv
END SUB
The program contains a fudge, using 1 to represent the first of possibly two additional black cards, besides the (lowest) spade, and also as later, in printing, to represent that first card, when it was discovered in building the program that there could be only one additional black card.
Puzzle from Giant Book of Mensa Mind Challenges, by Todd Johnson, "Nearly Impossible Brain Bafflers" chapter, page 191.
|