_TITLE "Buffon Pi Calc " 'b+ 2020-08-2 '2020-08-02 try this with Buffon Pi Calc pi ~ 2 * nTrials / nCross from
' pi ~ 2*L*N/(T*H) L=length of needle, T=spacing between lines N = Number of trials (or pins) H = number that cross line
CONST xmax
= 800, ymax
= 600 L = 100 ' both pin length and line spacing
N = 0 ' number of trials
C = 0 ' number of pins that cross the line
'SS = 0 ' pin head and point lay in Same Space
'redraw lines
'drop a random pin
N = N + 1 ' another trial pin
'did our pin cross a line
IF py2
>= 100 * INT(py1
/ 100) + L
THEN C
= C
+ 1 IF py1
>= 100 * INT(py2
/ 100) + L
THEN C
= C
+ 1 'FOR y = 0 TO _HEIGHT - 1 STEP L
' IF py1 >= y AND py1 < y + L THEN ' one side of pin is between y and y + L
' IF py2 >= y AND py2 < y + L THEN ' the pin did NOT cross a line both the head and point lay in same space
' SS = SS + 1
' EXIT FOR ' speed up a little
' END IF
' END IF
'NEXT
'C = N - SS
'Print results of trials