"Betting on Hamlet"

Highlight the following code and save it as a text file called HAMLET.BAS
Put it in the same folder as your GW-BASIC program. Load it and run it.

10 'Hamlet - the fencing match
20 CLEAR :CLS :KEY OFF
30 PRINT,"Shakespeare's 'Hamlet' - the fencing match."
40 PRINT "A program to analyse the bet wagered by Claudius"
50 PRINT "on the fencing match between Hamlet and Laertes." :PRINT
60 PRINT "Claudius bets that Laertes cannot exceed Hamlet by 3 hits in 12 passes."
70 PRINT "Because Laertes is nominally a better fencer than Hamlet,"
80 PRINT "Claudius has laid on odds of 12 for 9. Is this a good bet?" :PRINT
90 '
100 RANDOMIZE TIMER
110 PRINT "      H-wins     L-wins   H-profit   L-profit    H-gain %"
120 PASSES=12                        'the maximum number of plays in a game
130 GAMES=10000                      'test it for a large number of games
140 FOR CYCLE=1 TO 10                'show several cycles of games
150    HH=0 :LL=0
160    FOR K=1 TO GAMES
170       H=0 :L=0 :N=0
180       FOR N=1 TO PASSES
190          P=INT(8*RND+1)
200          IF P <= 3 THEN H=H+1 ELSE L=L+1
210          IF H=5 OR L=8 THEN 230
220       NEXT N
230       IF H=5 THEN HH=HH+1 ELSE LL=LL+1
240    NEXT K
250    PRINT USING "###########";HH;LL
260    HT=HT+HH :LT=LT+LL
270 NEXT CYCLE
280 PRINT USING "###########";HT;LT;
290 PRINT USING "###########";HT*12;LT*9;
300 PERCENT=(HT*12-LT*9)/(HT*12+LT*9)*100
310 PRINT USING "########.##";PERCENT :PRINT
320 PRINT,USING "###.##";PERCENT;
330 PRINT "% shows that Claudius has made a ";
340 IF PERCENT > 0 THEN PRINT "good bet." ELSE PRINT "bad bet."
350 END

Previous | Top | Home | Next