Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 5 rem estimation of pi using monte carlo simulation
- 10 rem implemented in basic v2 for c64 by felice nardella
- 15 t=ti
- 20 poke53280,11:s=8192
- 25 poke53272,peek(53272)or8:poke53265,peek(53265)or32
- 30 gosub220
- 35 rem clear color ram
- 40 cb$="pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp"
- 45 cb$=cb$+cb$:cb$=cb$+left$(cb$,121)
- 50 print"{clear}"cb$cb$cb$cb$;:print"ppp";:poke2023,16
- 55 tw(0)=1:fori=1to7:tw(i)=tw(i-1)*2:next
- 60 rem fori=1024to2023:pokei,208:next
- 65 goto95
- 70 rem plot x,y
- 75 p=s+320*int(y/8)+8*int(x/8)+(yand7)
- 80 pokep,peek(p)ortw(7-(xand7))
- 85 return
- 90 rem plot square
- 95 y=0:forx=0to199:gosub75:next
- 100 y=199:forx=0to199:gosub75:next
- 105 x=0:fory=0to199:gosub75:next
- 110 x=199:fory=0to199:gosub75:next
- 115 rem monte carlo
- 120 z=rnd(-ti):pn=10000
- 125 for i=0 to pn
- 130 y=int(rnd(1)*200)
- 135 x=int(rnd(0)*200)
- 140 if x*x+y*y<40000 then in=in+1:gosub75
- 145 next
- 150 rem time calc
- 155 te=ti-t:poke53280,15
- 160 rem wait for a key
- 165 poke198,0:wait198,1
- 170 gosub220
- 175 rem turn graphics off
- 180 printchr$(147)"total dots:"pn
- 185 print"internal dots:"in:print"external dots:"pn-in:print
- 190 print"estimated pi ="4*in/pn:print
- 195 print"total time:"te/3600"min"
- 200 poke53265,peek(53265)and(223)
- 205 poke53272,21:poke53280,14
- 210 end
- 215 rem clear graphic ram
- 220 cb$=""
- 225 p1=peek(51):p2=peek(52)
- 230 poke51,64:poke52,63
- 235 forcn=1to125:cb$=cb$+chr$(0):next
- 240 poke51,p1:poke52,p2
- 245 return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement