Skip to content

Instantly share code, notes, and snippets.

@youqad
Last active July 25, 2020 11:11
Show Gist options
  • Save youqad/bdf4fe884cac5b5d8639e5060c88baa7 to your computer and use it in GitHub Desktop.
Save youqad/bdf4fe884cac5b5d8639e5060c88baa7 to your computer and use it in GitHub Desktop.
WebPPL: Monty Hall (Solution 1: doesn't resort to any "without loss of generality" argument)
var MontyHall = function () {
var car = randomInteger({n: 3})
var our_choice = randomInteger({n: 3})
var all_doors_but = function (d1, d2) {
return filter(function(d){return d != d1 & d != d2 }, [0,1,2])
}
var monty = categorical({vs: all_doors_but(car, our_choice)})
var door_not_opened = all_doors_but(monty, our_choice)[0]
return car == door_not_opened ? "change wins": "keep wins"
}
viz(Infer(MontyHall))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment