-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
69 lines (57 loc) · 2.13 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.CodeDom;
using System.Collections.Generic;
namespace MontyHall
{
internal class Program
{
public static void Main(string[] args)
{
var m = ~0 << 3;
var rnd = new Random();
var stick = 0.0;
var twist = 0.0;
var n = 10000000;
var states = new[] {0b100, 0b010, 0b001};
for (var i = 0; i < n; i++)
{
var win = states[rnd.Next(0, 3)];
var player = 1 << rnd.Next() % 3;
var opened = 0;
if (player == win)
{
do
{
opened = 1 << (rnd.Next() % 3) & (~win - m);
} while (opened == 0);
}
else
{
opened = (win | player) ^ 0b111;
}
var option = ~(player | opened) - m;
/*Console.WriteLine($"win : {Convert.ToString(win, 2).PadLeft(3, '0')}");
Console.WriteLine($"player : {Convert.ToString(player, 2).PadLeft(3, '0')}");
Console.WriteLine($"opened : {Convert.ToString(host, 2).PadLeft(3, '0')}");
Console.WriteLine($"option : {Convert.ToString(option, 2).PadLeft(3, '0')}");*/
if ((player & win) > 0)
{
stick += 1;
//Console.WriteLine("stick");
}
else if ((option & win) > 0)
{
twist += 1;
//Console.WriteLine("twist");
}
else
{
//Console.WriteLine("lost");
}
//Console.WriteLine("---");
}
Console.WriteLine($"stick: {String.Format("{0:F}", stick/n)}");
Console.WriteLine($"twist: {String.Format("{0:F}", twist/n)}");
}
}
}