1/* 2Program describing the Monty Hall puzzle which gets its name from the TV game 3show hosted by Monty Hall. A player is given the opportunity to 4select one of three closed doors, behind one of which there is a prize. 5Behind the other two doors are empty rooms. 6Once the player has made a selection, Monty is obligated to open one of the 7remaining closed doors which does not contain the prize, showing that the room 8behind it is empty. He then asks the player if he would like to switch 9his selection to the other unopened door, or stay with his original choice. 10Here is the problem: Does it matter if he switches? 11 12From Chitta Baral, Michael Gelfond, and Nelson Rushton. (2009) 13"Probabilistic reasoning with answer sets." 14Theory and Practice of Logic Programming 9.01, 57-144. 15Simplified program code by Richard de Rozario. 16 17Casting the game into a probability logic program reveals the key to the puzzle. 18Namely, that Monty will reveal a goat no matter what the player picks. 19Therefore, the probability of revealing a goat is 100%. In turn, 20this means that getting a car when switching depends solely on having 21picked a goat originally -- which of course had a probability of 2/3. 22*/ 23 24:- use_module(library(pita)). 25:- pita. 26:- begin_lpad. 27 28picked(car)1/3. 29picked(goat):- \+ picked(car). 30 31revealed(goat):- picked(_). 32 33switch_gets(car):- picked(goat), revealed(goat). 34 35:- end_lpad. 36 37main:- 38prob(switch_gets(car),P), 39format('Probability that switching gets the car is ~2f',[P]).
?- main.
*/