Problem Statement
We believe that whenever two adjacent particles transform to have identical states, they annihilate each other. We will call a pair of particles "unstable" if there is a sequence of transformations that could lead to an annihilation.
We need to estimate the probability that two adjacent particles are unstable.
To make this specific, we will choose two
particles and assume that each is equally likely to have any initial state between
-4999 and 5000 inclusive (a state of 0 is possible). Create a class AntiMatter
that contains a method unstable that receives a
The method should return the probability as a
Definition
- Class:
- AntiMatter
- Method:
- unstable
- Parameters:
- int[]
- Returns:
- String
- Method signature:
- String unstable(int[] xform)
- (be sure your method is public)
Constraints
- xform will contain exactly 4 elements (not necessarily distinct).
- Each element in xform will be between -10,000 and 10,000 inclusive.
Examples
{6,6,6,6}
Returns: ".00010000"
Every transition of each particle increases its state by 6, so unless the two particles start with identical states and annihilate immediately, they can never reach identical states. There are 10,000 pairs of particles that immediately annihilate.
{0,0,0,0}
Returns: ".00010000"
{2,-3,4,-5}
Returns: "1.00000000"
{9993,-7,743,-7}
Returns: ".00400000"
{-10000,9997,9999,10000}
Returns: "1.00000000"
{-10000,1,1,10000}
Returns: "1.00000000"
{1,-1,1,-1}
Returns: ".50000000"
If two particles initially have states that differ by an odd number, then after every transition they will still differ by an odd number, so they can never annihilate. But if they start with an even difference in their states, then the lower one can always increase its state by 1 while the higher one decreases by 1, leading eventually to annihilation. Since half of the 100,000,000 pairs are either even-even or odd-odd, 50,000,000 are unstable.
{0,1,-1,1}
Returns: "1.00000000"
The lower particle can stay at its initial state by transforming by 0 each time, while the higher particle transforms by -1 until annihilation occurs.
{0,0,0,792}
Returns: ".00126448"
{-10000,-10000,-10000,-9999}
Returns: "1.00000000"
{7000,8000,9000,10000}
Returns: ".00100000"
{7000,8004,9000,10000}
Returns: ".25000000"
{7000,8004,7000,7000}
Returns: ".00099640"
{7000,8004,7000,7006}
Returns: ".50000000"
{-7000,-8029,-7000,7000}
Returns: ".14285716"
{-72,60,48,-480}
Returns: ".08333336"
{ 0, 0, 0, 792 }
Returns: ".00126448"
{ -10000, 10000, 0, 3 }
Returns: "1.00000000"
{ 0, 12, 15, 19 }
Returns: "1.00000000"