/ Published in: Groovy
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* * 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}%." } }