Monty-Hall问题的Monte-Carlo模拟
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Monty-Hall问题的Monte-Carlo模拟相关的知识,希望对你有一定的参考价值。
/* * Monte Carlo simulation for the Monty Hall Problem: * http://en.wikipedia.org/wiki/Monty_Hall_problem. */ import java.util.* class MontyHall { MontyHall() { } RANDOM.nextInt(3) } } // Return true if the player won by staying // with their first choice, false otherwise. won(pick) } // Return true if the player won by switching, false otherwise. won(switched_pick) } // Return true if the player's final pick hides a car, false otherwise. doors[pick] == 'car' } ITERATIONS.times { } println "Staying: ${staying_rate}%." println "Switching: ${switching_rate}%." } }
以上是关于Monty-Hall问题的Monte-Carlo模拟的主要内容,如果未能解决你的问题,请参考以下文章