RANDOMIZE TIMER CLS 'Variables explained 'a% used to run the loops ie the ath run 'p% an array that represents the pack of cards has value 1 or 0 for red or black 'w% win in specific game 'tw& total win so far PRINT "v1.008" PRINT "This program is designed to help in the solving of riddle number 14 from" PRINT "my website http://puzzles.nigelcoldwell.co.uk" PRINT " " PRINT "#14:" PRINT "You have 52 playing cards (26 red, 26 black). You draw cards one by one." PRINT "A red card pays you a dollar. A black one fines you a dollar. You can" PRINT "stop any time you want. Cards are not returned to the deck after being" PRINT "drawn. What is the optimal stopping rule in terms of maximizing expected" PRINT "payoff? Also, what is the expected payoff following this optimal rule?" PRINT " " PRINT "This program runs the simulation 'I will quit if i get x amount of Dollars" PRINT "ahead'" PRINT "(Break key to pause before 1,000,000 runs)" PRINT " " DIM p%(53) p%(53) = 1 tw& = 0 n& = 0 INPUT "Enter quit level, eg. 1, 2, 3 Dollars etc. (0 to quit)"; q% IF q% = 0 THEN END FOR n& = 1 TO 1000000 'Build Pack FOR a% = 1 TO 52 p%(a%) = 0 NEXT a% FOR a% = 1 TO 26 1 b% = INT(RND * 52) + 1 IF p%(b%) THEN GOTO 1 ELSE p%(b%) = 1 NEXT a% n& = n& + 1 w% = 0 FOR a% = 1 TO 52 IF p%(a%) THEN w% = w% - 1: PRINT ; "B"; ELSE w% = w% + 1: PRINT ; "R"; IF w% = q% THEN GOTO 2 NEXT a% 2 tw& = tw& + w% LOCATE CSRLIN, 54, 0 PRINT ; "w:"; w%; " Avg:"; (INT(tw& / n& * 100000)) / 100000 NEXT n& PRINT "1,000,000 runs completed...." DO UNTIL INKEY$ <> "" LOOP RUN