home *** CD-ROM | disk | FTP | other *** search
/ Ahoy 1985 August / Ahoy_Magazine_85-08_1985_Double_L.d64 / needles (.txt) < prev    next >
Commodore BASIC  |  2022-10-26  |  644b  |  28 lines

  1. 0 rem << rr20-1 >>
  2. 1 print"[147]":poke53280,6:poke53281,1:poke646,6
  3. 2 rem  --   needles   --
  4. 3 rem   rupert report #20
  5. 4 rem
  6. 10 rem - simulate the buffon needle
  7. 11 rem   experiment.  drop needles of
  8. 12 rem   length l on floorboards of
  9. 13 rem   width h.  success if needle
  10. 14 rem   lands on a crack. probability
  11. 15 rem   of landing on a crack is
  12. 16 rem   (2*l)/(h*pi)
  13. 17 rem
  14. 20 h=1 :l=h :tries=1 :wins=1 :k=2*l/h
  15. 30 print chr$(147)tab(12)"< tries"
  16. 40 print tab(12)"< pi"
  17. 50 print tab(12)"< avg"
  18. 60 y0=h*rnd(0)
  19. 70 a=rnd(0)*30000
  20. 80 y=l*sin(a)+y0
  21. 90 if y>h or y<0 then wins=wins+1
  22. 100 pi=k*tries/wins
  23. 110 ttl=ttl+pi : avg=ttl/tries
  24. 120 print chr$(19)tries : print pi
  25. 130 print avg
  26. 140 tries=tries+1
  27. 150 goto 60
  28.