Terrapin Resources

Coin Flips

Have you ever wondered, when you flip a coin, whether a coin falls more often on the head or the tail? How often would you have to flip the coin to achieve a probability of 50 percent (both sides fall equally often)?

Probability theory says it should be even but the experiment shows it rarely comes out even. This should lead into a discussion of what is the value of the theory, perhaps other than benefitting a casino?

Well, here is the program to help you out. Load the program and enter `COINFLIPS` and the number of times, preferably not more often than 700 times. The program prints each flip and summarizes the result at the end.

COINFLIPS.lgo

``````TO COINFLIPS :NUM
CLEARTEXT
REM [ENTER NUMBER OF COINFLIPS DESIRED BUT NOT MORE THAN MAX OF SEVEN HUNDRED]
PR (SE [TOSSING A COIN] :NUM [TIMES. PLEASE WAIT...])
PR []
MANY.FLIPS :NUM 0 0
END

TO MANY.FLIPS :NUM :HEADS :TAILS
IF :NUM = 0 THEN PR [] PR [] PR (SE [HEADS =] :HEADS [.....] [TAILS =] :TAILS) STOP
IF FLIP = "HEADS THEN PRINT "H MANY.FLIPS :NUM - 1 :HEADS + 1 :TAILS ELSE PRINT "T MANY.FLIPS :NUM - 1 :HEADS :TAILS + 1
END

TO FLIP
OUTPUT PICK.ONE [HEADS TAILS]
END

TO PICK.ONE :OBJECT
; ----------------------------------
; picks one item from a word or list
; ----------------------------------
OUTPUT ITEM (RANDOM COUNT :OBJECT) :OBJECT
END

TO REM :COMMENTS
END
``````

 Procedure COINFLIPS Description Flip a coin to see how often heads or tails will fall Level Beginner Tags Math, Random