帮我看看这是什么语言的写法

问题描述:

帮我看看这是什么语言的写法
# How many times should we run this experiment?
iters = 1000
results = rep(0,iters)
for(i in 1:iters) {
# A random permutation:
boxes = sample(1:100,100)
# Labels for our prisoners
prisoners = 1:100
# Track how many "winners" we have
foundIt = 0
# Main loop over the prisoners
for(prisoner in prisoners) {
# Track the prisoners path
path = c(prisoner)
tries = 1
# Look first in the box that matches your own number
inBox = boxes[prisoner]
while(tries < 50) { path = c(path,inBox) if(inBox == prisoner) { #cat("Prisoner",prisoner,"found her number on try",tries,"\n") foundIt = foundIt + 1 break; } else { # Follow that number to the next box inBox = boxes[inBox] } tries = tries+1 } # cat("Prisoner",prisoner,"took path",paste(path,collapse=" -> "),"\n")
}
# How many prisoners found their numbers?
cat("A total of",foundIt,"prisoners found their numbers.\n")
flush.console()
results[i] = foundIt
}
hist(results,breaks=100,col="blue")
1个回答 分类:综合 2014-10-18

问题解答:

我来补答
java
 
 
展开全文阅读
剩余:2000