思いっきり直感に反す件。プログラムで書いてみた。おお、分かりやすい。ようは選び直すことで当たりが外れに、外れが当たりになると。だから当たり外れの確立が逆になる。
import std.random, std.stdio; bool montyhall(bool is_change){ bool[3] box; int hit = rand()%3; box[hit] = true; int user_choice = rand()%3; if(is_change){ if(box[user_choice]){ int i = rand()%2; if(i == user_choice) i++; user_choice = i; }else user_choice = hit; } return box[user_choice]; } void main(){ { int c, o; for(;c<1000;c++) o+=montyhall(false); writefln("%s/%s (%s)",o,c,cast(double)o/c); } { int c, o; for(;c<1000;c++) o+=montyhall(true); writefln("%s/%s (%s)",o,c,cast(double)o/c); } }