# pi-greco n <- 100000; xmin <- -0.5; xmax <- 0.5; r <- (xmax-xmin)/2 out <- runif(n,min=xmin,max=xmax) x <- matrix(out,ncol=2) d <- x[,1]^2 + x[,2]^2 l <- d<=(r^2); m <- d>(r^2) win.graph(7,7.8) # cosė č quadrato plot(c(xmin,xmax),c(xmin,xmax),type="n") plot(x[l,1],x[l,2]) points(x[m,1],x[m,2],col="red",pch=19) p <- sum(l)/length(l) p*4