#bbcmicrobot Simulate coinflips to calculate pi 🚀
(long, so easy to understand!)
FOR L=13TO18: ?L=?-444: NEXT
C%=0
A=0
REPEAT
O=FNround(1)
C% = C% + 1
REM PRINT "Round", C%
REM PRINT "Game result", O
T=A * (C% - 1)
A=(T + O) / C%
PRINT "Pi after "; C%; " rounds is "; A * 4
UNTIL C% > 1000
END
DEF FNround(X)
REM flip coins until you've got more heads than tails, then return heads/flips
F%=0
H%=0
T%=0
REPEAT
R=RND(2)
IF R=1 THEN H% = H% + 1: ELSE T% = T% + 1
F% = F% + 1
UNTIL H% > T%
=H%/F%