Unformatted text preview: Darts D BULLSEYE<function() B { cat("\n") cat("*****BULLS EYE*****","\n") cat("The Goal: The area of the circle in the square (1,1),(1,1),(1,1),(1,1)","\n") T cat(" ","\n") cat("\n") #draw the circle # CIRCLE("CIRCLE",0) #Determine the number of darts thrown ANSWER < readline("What is the sample size? ") r SSize < as.numeric(ANSWER) cat("\n") ANSWER < readline("Fire darts one at a time? ") if (substr(ANSWER, 1, 1) == "y") { cnt < 0 for (i in 1:SSize) 1 { ANSWER < readline("Hit ENTER to FIRE WHEN READY!") cat("\n") cat("FIRE!!!\n") c cat("\n") x=2*runif(1)1 y=2*runif(1)1 points(x,y) if (x^2+y^2<=1) cnt=cnt+1 ( } pct < cnt/SSize } else { xdarts<2*runif(SSize)1 ydarts<2*runif(SSize)1 y points(xdarts,ydarts) #darts in circle circle < xdarts^2+ydarts^2 x pct<length(circle[circle<=1])/SSize } return(4*pct) r }BULLSEYE()...
View
Full Document
 Spring '09
 Xu(Sunny)Wang
 Interior, outer circle lines, inner circle lines

Click to edit the document details