#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define MAX 1000000

int main()
{
	int porte[3];
	int r, c;
	
	unsigned long long int nwins = 0;
	unsigned long long int i;
	unsigned long long int p;
	
	srand(time(NULL));
	
	for ( i = 0; i < MAX; i++ )
	{
		r = rand();
		
		if ( r % 2 == 0 )
			porte[0] = 1;
		else
			porte[0] = 0;
	
		r = rand();
	
		if ( porte[0] == 0 && r % 2 != 0 )
			porte[1] = 1;
		else
			porte[1] = 0;
	
		if ( porte[0] == 1 || porte[1] == 1 )
			porte[2] = 0;
		else
			porte[2] = 1;
		
		// giocatore: r varra' 0, 1 o 2
	
		r = rand() % 3;
	
		// conduttore: c avra' il valore (0,1,2) della porta libera con la capra
	
		c = rand() % 3;
	
		while ( c == r || porte[c] == 1 )
			c = (c + 1) % 3;
		
		// cambio porta: r varra' (0,1,2) il valore della porta libera
	
		r = (r + 1) % 3;
	
		if ( r == c )
			r = (r + 1) % 3;
			
		// controllo se la porta scelta dal giocatore vale 1, cioe' l'automobile
	
		if ( porte[r] == 1 )
			nwins++;
	}
	
	printf("%llu vittorie su %llu\n", nwins, i);
	
	p = (nwins * 100) / i;
	
	printf("prob:\t%llu %%\n", p);
	
	return 0;
}

