このループは並列実行できますか(2)?
前のサイコロゲームがとても気に入ったので、何度もプレイしたくなりました。元のコードを関数で包みます。
play <- function() {
total <- no_of_rolls <- 0
while(total < 10) {
total <- total + sample(1:6, 1)
# If even. Reset to 0
if(total %% 2 == 0) total <- 0
no_of_rolls <- no_of_rolls + 1
}
no_of_rolls
}
そして、ゲームを実行するためのループを作ります。
results <- numeric(100)
for(i in seq_along(results))
results[i] <- play()
この for ループは(簡単に)並列実行できると思いますか?
この演習はコースの一部です
