作业帮 > 综合 > 作业

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

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/12 16:14:17
帮我看看这是什么语言的写法
# 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")
帮我看看这是什么语言的写法
java