private static readonly Random Random = new Random();
private readonly double _angle;
private bool _measured = false;
public HPParticle(double angle)
public bool GetValue(int sensorPosition)
throw new InvalidOperationException("Измерить можно только один раз!");
return IsDetectedBySensor(sensorPosition, _angle);
private static bool IsDetectedBySensor(int sensorPosition, double angle) =>
Random.NextDouble() < ComputeProbability(angle - Math.PI * 2 / 3 * sensorPosition);
private static double ComputeProbability(double angle) =>
Math.Pow(Math.Cos(angle), 2);
public class EntanglementHPParticles
public HPParticle First { get; private set; }
public HPParticle Second { get; private set; }
public EntanglementHPParticles()
var angle1 = 2 * Math.PI * Random.NextDouble();
var angle2 = angle1 + Math.PI / 2;
First = new HPParticle(angle1);
Second = new HPParticle(angle2);
private WFCParticle _entangledParticle;
private bool _measured = false;
public WFCParticle(WFCParticle entangledParticle)
_entangledParticle = entangledParticle;
if (entangledParticle != null)
entangledParticle._entangledParticle = this;
public bool GetValue(int sensorPosition)
throw new InvalidOperationException("Измерить можно только один раз!");
var sensorAngle = Math.PI * 2 / 3 * sensorPosition;
_angle = 2 * Math.PI * Random.NextDouble();
var result = IsDetectedBySensor(sensorAngle, _angle.Value);
_angle = sensorAngle + Math.PI / 2;
if (_entangledParticle != null)
_entangledParticle._angle = _angle + Math.PI / 2;
_entangledParticle._entangledParticle = null;
_entangledParticle = null;
private static bool IsDetectedBySensor(double sensorAngle, double angle) =>
Random.NextDouble() < ComputeProbability(angle - sensorAngle);
private static double ComputeProbability(double angle) =>
Math.Pow(Math.Cos(angle), 2);
public class EntanglementWFCParticles
public WFCParticle First { get; private set; }
public WFCParticle Second { get; private set; }
public EntanglementWFCParticles()
First = new WFCParticle(null);
Second = new WFCParticle(First);
public static void Main(string[] args)
private static void Experiment1()
var totalAttempts = 10000;
for (int attemptNumber = 1; attemptNumber <= totalAttempts; attemptNumber++)
var entanglementParticles = new EntanglementHPParticles();
int firstSensorPosition = 1;
int secondSensorPosition = 1;
bool firstValue = entanglementParticles.First.GetValue(firstSensorPosition);
bool secondValue = entanglementParticles.Second.GetValue(secondSensorPosition);
if (firstValue != secondValue)
Console.WriteLine("Эксперимент №1: {0}% значений не совпало", (double)disparityCount / totalAttempts * 100);
private static void Experiment2()
var totalAttempts = 10000;
for (int attemptNumber = 1; attemptNumber <= totalAttempts; attemptNumber++)
var entanglementParticles = new EntanglementWFCParticles();
int firstSensorPosition = 1;
int secondSensorPosition = 1;
bool firstValue = entanglementParticles.First.GetValue(firstSensorPosition);
bool secondValue = entanglementParticles.Second.GetValue(secondSensorPosition);
if (firstValue != secondValue)
Console.WriteLine("Эксперимент №2: {0}% значений не совпало", (double)disparityCount / totalAttempts * 100);
private static void Experiment3()
var totalAttempts = 10000;
for (int attemptNumber = 1; attemptNumber <= totalAttempts; attemptNumber++)
var entanglementParticles = new EntanglementHPParticles();
int firstSensorPosition = Random.Next(0, 3);
int secondSensorPosition = Random.Next(0, 3);
bool firstValue = entanglementParticles.First.GetValue(firstSensorPosition);
bool secondValue = entanglementParticles.Second.GetValue(secondSensorPosition);
if (firstValue != secondValue)
Console.WriteLine("Эксперимент №3: {0}% значений не совпало", (double)disparityCount / totalAttempts * 100);
private static void Experiment4()
var totalAttempts = 10000;
for (int attemptNumber = 1; attemptNumber <= totalAttempts; attemptNumber++)
var entanglementParticles = new EntanglementWFCParticles();
int firstSensorPosition = Random.Next(0, 3);
int secondSensorPosition = Random.Next(0, 3);
bool firstValue = entanglementParticles.First.GetValue(firstSensorPosition);
bool secondValue = entanglementParticles.Second.GetValue(secondSensorPosition);
if (firstValue != secondValue)
Console.WriteLine("Эксперимент №4: {0}% значений не совпало", (double)disparityCount / totalAttempts * 100);