home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ahoy 1985 August
/
Ahoy_Magazine_85-08_1985_Double_L.d64
/
needles
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-10-26
|
644b
|
28 lines
0 rem << rr20-1 >>
1 print"[147]":poke53280,6:poke53281,1:poke646,6
2 rem -- needles --
3 rem rupert report #20
4 rem
10 rem - simulate the buffon needle
11 rem experiment. drop needles of
12 rem length l on floorboards of
13 rem width h. success if needle
14 rem lands on a crack. probability
15 rem of landing on a crack is
16 rem (2*l)/(h*pi)
17 rem
20 h=1 :l=h :tries=1 :wins=1 :k=2*l/h
30 print chr$(147)tab(12)"< tries"
40 print tab(12)"< pi"
50 print tab(12)"< avg"
60 y0=h*rnd(0)
70 a=rnd(0)*30000
80 y=l*sin(a)+y0
90 if y>h or y<0 then wins=wins+1
100 pi=k*tries/wins
110 ttl=ttl+pi : avg=ttl/tries
120 print chr$(19)tries : print pi
130 print avg
140 tries=tries+1
150 goto 60