#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
int main()
{
int i,j , ansDoor,selectedDoor,openedDoor, oldSelectedDoor;
int result[2]={ 0 };
//plant a seed
srand( time(NULL) );
for( j = 0 ; j < 10 ; j++ )
{
result[0] = result [1] = 0;
for ( i = 0; i < 100000 ; i++ )
{
//random right door
ansDoor = rand() % 4;
// now give a selected door
selectedDoor = rand() % 4;
//if we confirm that door.
if( selectedDoor == ansDoor)
result[0]++;
//collect result
if( selectedDoor != ansDoor)
result[1]++;
}
//print
printf("\n%d\nnochange = %d (%.2f) \nchange = %d (%.2f)\n from %d times",j,
result[0] , ((float)result[0]/i)*100 ,
result[1] , ((float)result[1]/i)*100 , i );
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHRpbWUuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgppbnQgbWFpbigpCnsKCWludCBpLGogLCBhbnNEb29yLHNlbGVjdGVkRG9vcixvcGVuZWREb29yLCBvbGRTZWxlY3RlZERvb3I7CglpbnQgcmVzdWx0WzJdPXsgMCB9OwoJCgkvL3BsYW50IGEgc2VlZAoJc3JhbmQoIHRpbWUoTlVMTCkgKTsKCWZvciggaiA9IDAgOyBqIDwgMTAgOyBqKysgKQoJewoJCXJlc3VsdFswXSA9IHJlc3VsdCBbMV0gPSAwOwoJCWZvciAoIGkgPSAwOyBpIDwgMTAwMDAwIDsgaSsrICkKCQl7CgoJCQkvL3JhbmRvbSByaWdodCBkb29yCgkJCWFuc0Rvb3IgPSByYW5kKCkgJSA0OwoJCQoJCQkvLyBub3cgZ2l2ZSBhIHNlbGVjdGVkIGRvb3IKCQkJc2VsZWN0ZWREb29yID0gcmFuZCgpICUgNDsKCgkJCS8vaWYgd2UgY29uZmlybSB0aGF0IGRvb3IuCgkJCWlmKCBzZWxlY3RlZERvb3IgPT0gYW5zRG9vcikKCQkJCXJlc3VsdFswXSsrOwoKCQk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