Problem Statement
We have a dynamic system, in which real values are generated by the following rule: xt+1 = f(xt) where f is the function
f(x) = 3x (for x in I_Zero) (3-3x)/2 (for x in I_One)The trajectory of a value c is the sequence of real values that would be generated by the system starting with c. These would be c, f(c), f(f(c)), etc. The "itinerary" of c is defined to be the sequence of 0's and 1's indicating whether the corresponding trajectory values are in I_Zero or I_One.
For example, the trajectory of 1/2 is 1/2,3/4,3/8,15/16,3/32,9/32, ... so its itinerary is 1,1,1,1,0,0,...
Given a value and the itinerary of an unknown value c, we would like to determine whether the given value is less than or greater than c. Since an itinerary is an infinite sequence, we will be given only the first part of an itinerary, so it may be impossible to determine whether the given value is smaller or larger than c.
Create a class Symbolic that contains a method compare that is given value as a decimal
Definition
- Class:
- Symbolic
- Method:
- compare
- Parameters:
- String, int[]
- Returns:
- int
- Method signature:
- int compare(String value, int[] itin)
- (be sure your method is public)
Constraints
- value will contain between 2 and 20 characters inclusive.
- value will consist of a decimal point followed by digits '0'-'9'.
- itin will contain between 1 and 50 elements inclusive.
- Each element of itin will be 0 or 1.
Examples
".5"
{1,1,1,1,0}
Returns: 0
The first elements of the itinerary of 0.5 match the values in itin, so we cannot determine whether 0.5 is less than, equal to, or greater than c.
".300000"
{1,1,1,1,0}
Returns: -1
0.3 is less than 1/3 so it is in I_Zero. c is between 1/3 and 1.0 since its itinerary starts in I_One. So 0.3 is less than c.
".6"
{1,1,0,1,0,0}
Returns: 1
The trajectory of .6 is .6,.6,.6,.6,... If c were greater than or equal to .6, then f(c) would be less than or equal to (3 - 3*.6)/2 = .6 and f( f(c) ) would be greater than or equal to .6 which contradicts the fact that the third element of itin is 0. Therefore, .6 must be greater than c.
".713"
{0,1,1,1,1,1,1,1,1,1,1,1,1,1}
Returns: 1
".12"
{0,1,1,1,1,1,1,1,1,1,1,1,1,1}
Returns: -1
".1111111111111111111"
{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0}
Returns: -1
".00"
{0,0,0,0,0}
Returns: 0
Indeterminate: value may either be less than or equal to c. (It cannot be greater than c since a number less than .0 has no itinerary.)
".3333333333333332"
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
Returns: 0
".3333333333333332"
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
Returns: -1
".3141284799582800052"
{0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,1,1,0,0,1,1,1,1,1,0,1,1,1,0,0,0,0, 0,0,1,1,1,1,0,0,1,0,1,0,0,0,1}
Returns: 0
".1111111111111111111"
{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1}
Returns: 0
Be careful about the precision of your calculations.
".3333333333333333333"
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1}
Returns: 0
".9337847345123329165"
{1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,1,1,0,1,1,0,1,1,0,0,0,1,0,0,0,0,0,0,1,0,1,1,1,0,0,1,0,0,0,1,0,1,1,0}
Returns: 0
".5362526285178392308"
{1,1,1,1,0,1,0,1,1,1,0,0,1,1,1,1,1,0,1,0,1,1,0,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0,1,1,1,0,1,1,0,1,0,1,1,1}
Returns: 0
".9644084306194855008"
{1,0,0,1,1,0,1,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,1,0,1,1,1,1,0,1,0,1,0,0,0,0,1,1,1,1,0,1,1,0,0,1,1,1,1,1}
Returns: 0
".9755798369577898469"
{1,0,0,0,1,0,0,0,1,1,0,1,1,1,0,0,1,1,1,0,0,1,1,0,0,1,0,0,0,1,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,1,1,0,1,1}
Returns: 0
".8603301333351046049"
{1,0,1,1,1,1,1,1,1,0,1,1,0,0,0,0,1,0,0,1,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,1,1,1,1,1,0,0,1,0,0,0,1,1,0}
Returns: 0
".9881311704506321684"
{1,0,0,0,1,1,0,1,0,0,0,0,1,1,1,1,1,0,1,1,1,1,1,0,1,0,0,1,1,0,0,0,1,1,1,1,0,0,0,0,1,0,1,0,0,0,0,1,0,1}
Returns: 0
".7804238463687224652"
{1,0,1,0,0,0,1,1,1,1,0,0,0,0,0,1,0,0,1,0,1,0,1,1,1,1,0,1,1,1,1,0,1,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1}
Returns: 0
".8707993862634372893"
{1,0,1,1,1,1,1,1,1,1,0,1,1,0,0,1,1,1,0,0,1,0,0,0,0,0,1,1,1,0,1,0,0,0,1,1,1,1,0,0,1,0,0,0,0,0,1,1,0,1}
Returns: 0
".8289841070925160663"
{1,0,1,1,1,0,0,0,1,1,1,0,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0,1,0,1,1,1,0,1,1,0,0,1,1}
Returns: 0
".2411789432099385569"
{0,1,1,1,0,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,0,1,0,1,1,1,1,0,0,0,1,0,1,0,0,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1}
Returns: 0
".8268444022356451988"
{1,0,1,0,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,1,0,0,1,1,0,0,0,0,1,0,0,1,1,1,0,1,1,0,0,0,1,1,0,1,0}
Returns: 0
".6774802845816602086"
{1,1,1,1,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,0,1,1,1,1,1,1,0,1,1,1,0,1,0,1,1,0,0,1,0,1,1,0,0,0,1,0,0,1,0,0}
Returns: 0
".4724292224692111385"
{1,1,0,1,0,0,1,0,1,0,1,0,0,1,1,1,1,1,1,1,0,1,1,1,0,1,0,1,0,1,1,1,1,0,0,1,1,1,1,0,1,0,1,1,0,0,1,0,1,0}
Returns: 0
".9419809138637860199"
{1,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,1,0,1,0,0,1,0,0,0,0,1,1,0,1,0,0,1,1,1,1,1,1,1,0,0,0,1,0,0,1,1,1,1,1}
Returns: 0
".9230682211052578645"
{1,0,1,1,0,0,0,1,0,1,0,0,0,1,1,1,1,1,1,1,0,1,1,0,0,1,1,0,0,1,1,1,1,1,1,0,0,0,0,0,1,1,0,1,1,1,0,0,0,1}
Returns: 0
".6240028192762211350"
{1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,0,1,1,0,1,1,1,1,1,0,0,0,0,1,0,1,0,0,1,1,1,0,1,0,1,1,1,1,1,0,1}
Returns: 0
".6785461876946973892"
{1,1,1,1,1,0,0,0,0,0,1,0,1,1,1,1,1,1,1,0,0,1,0,1,1,0,0,1,1,1,1,0,1,0,1,0,1,1,0,1,0,1,0,1,1,1,1,1,0,0}
Returns: 0
".2830517599654725705"
{0,1,0,1,1,1,1,1,0,0,0,0,0,1,1,0,1,1,0,0,1,0,0,1,0,1,1,1,1,0,0,0,1,1,0,1,0,0,0,1,1,0,0,0,1,1,0,0,1,0}
Returns: 0
".3000659453911322492"
{0,1,0,1,1,0,1,0,1,0,0,0,1,1,1,1,1,0,0,0,1,1,0,1,0,0,1,1,0,1,1,0,0,1,0,1,1,0,0,1,0,0,0,0,0,0,0,0,1,0}
Returns: 0
".9457298614193174488"
{1,0,0,1,1,1,0,1,1,0,1,0,1,1,1,0,0,1,0,0,0,1,1,0,0,0,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0,1,0,1,0,0,0,1,0,0}
Returns: 0
".4813469057634349963"
{1,1,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,1,0,1,1,1,0,1,0,0,1,0,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,1,1,0,0,1,0}
Returns: 0
".7911929487855286358"
{1,0,1,0,0,1,0,1,0,1,1,1,0,0,1,1,1,0,0,1,0,0,1,0,0,0,0,0,1,0,1,1,0,1,1,1,0,0,0,0,1,0,1,1,1,0,1,1,1,1}
Returns: 0
".3390638240282521827"
{1,1,0,0,0,1,1,0,0,0,1,0,1,1,0,1,0,1,0,1,0,0,0,1,0,0,0,1,1,0,1,1,0,0,1,1,0,0,1,1,0,1,1,0,0,1,0,0,0,0}
Returns: 0
".2580625690024678360"
{0,1,1,1,0,0,0,0,1,0,0,0,1,1,1,0,0,1,0,1,0,0,1,1,1,1,1,1,1,1,0,0,1,1,0,1,0,0,0,0,0,1,1,0,1,0,1,0,0,1}
Returns: 0
".9643447863572238128"
{1,0,0,1,1,0,1,0,0,0,0,0,1,1,0,0,0,0,0,1,0,1,1,1,0,0,0,1,0,0,1,0,1,0,0,0,0,0,1,1,1,0,1,0,1,0,0,1,1,1}
Returns: 0
".8049597386387869223"
{1,0,1,0,1,1,1,1,1,1,0,0,0,1,0,0,1,1,1,1,1,1,1,1,0,1,0,0,0,1,0,0,1,1,1,1,0,1,1,1,1,1,1,0,1,0,1,1,0,1}
Returns: 0
".9991075861137728968"
{1,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,1,1,0,1,0,1,1,0,0,0,0,1,0,0,0,1,1,1,1,0,1,0,1,1,0,0,0,0,0,1,1,1,0}
Returns: 0
".3898560289470892429"
{1,1,0,1,1,0,0,1,0,0,0,1,0,0,1,1,0,0,0,1,0,1,1,0,0,1,1,1,0,1,0,0,0,1,0,0,1,1,0,1,1,1,0,1,0,0,1,0,1,0}
Returns: 0
".5350615104907494978"
{1,1,1,1,0,1,0,1,0,1,1,1,0,1,1,1,1,0,0,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0,1,0,1,1,0,1,0,1,1,0,1,0}
Returns: 0
".3310793006217014837"
{0,1,0,0,0,0,1,0,1,0,1,0,1,1,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,0,1,1,1,1,0,1,1,0}
Returns: 0
".9867754279481600728"
{1,0,0,0,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,0,0,0,0,1,0,0,1,0,1,0,1,0,1,1,0,1,1,1,1,0,1,0,0,0,0,1,1,1,1,0}
Returns: 0
".7856869366387407640"
{1,0,1,0,0,1,1,0,1,0,0,0,0,1,0,1,0,1,0,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,0,1,0,1,1,1,0,0,0,0,0,1,1,1,0,0}
Returns: 0
".7760200481220967639"
{1,1,1,0,0,0,0,1,1,0,1,0,0,0,0,1,0,1,0,0,1,1,1,0,1,0,0,1,0,0,0,1,0,0,1,1,0,1,0,1,1,1,1,0,0,0,1,1,0,0}
Returns: 0
".9240992656503922512"
{1,0,1,1,0,0,0,1,1,1,1,0,0,1,0,1,0,1,1,1,0,0,1,0,1,1,1,1,0,0,1,1,0,1,1,1,0,1,1,1,0,0,0,1,0,0,1,1,1,1}
Returns: 0
".3129434013456734489"
{0,1,0,0,1,0,1,0,1,0,0,1,1,0,0,1,0,1,0,1,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1}
Returns: 0
".9315434992708631476"
{1,0,0,1,0,1,1,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,1,1,0,1,0,1,0,0,0,1,0,1,0,1,1,1,0,1,1,1,1,0,1,0,1,1,1,1}
Returns: 0
".7804159747568193776"
{1,0,1,0,0,0,1,1,0,1,0,0,0,0,1,1,1,1,1,1,0,0,0,1,1,1,0,1,0,0,1,1,1,0,0,1,1,1,1,0,1,1,0,0,1,1,1,0,0,0}
Returns: 0
".7820886612362630765"
{1,0,1,0,0,0,1,0,1,0,0,1,1,0,1,0,0,0,1,1,1,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,1,0,1,1}
Returns: 0
".3265551795154501198"
{0,1,0,0,0,1,0,1,0,1,0,0,1,0,0,0,1,1,0,1,0,0,0,1,0,0,1,1,1,0,1,0,0,1,0,1,1,1,1,1,0,0,0,0,0,1,1,0,1,0}
Returns: 0
".3615095083455664697"
{1,1,0,0,1,1,1,1,1,1,0,1,0,1,0,0,1,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0}
Returns: 0
".9987507170261542124"
{1,0,0,0,0,0,1,1,0,1,0,1,0,1,0,0,1,0,0,1,1,1,0,0,1,0,0,1,1,0,1,1,0,0,1,1,0,0,1,0,1,0,1,1,1,1,1,0,1,0}
Returns: 0
".3352315574774293125"
{1,1,0,0,0,0,1,1,0,0,0,1,1,1,0,0,1,1,0,0,0,1,1,0,1,0,0,0,1,0,1,0,1,1,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,1}
Returns: 0
".9160875821898907934"
{1,0,1,1,0,0,1,0,1,1,0,1,0,1,1,0,1,0,0,0,0,1,0,1,1,1,0,1,0,1,0,1,0,0,0,1,1,1,1,0,1,1,0,1,1,0,1,0,1,0}
Returns: 0
".2729051760439493013"
{0,1,0,1,0,1,0,1,1,1,0,0,0,1,1,1,0,0,1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,1,0,0,0,1,1,0}
Returns: 0
".8173662978280467240"
{1,0,1,0,1,0,1,0,1,1,1,1,0,0,0,0,1,0,0,1,0,1,1,1,0,1,0,1,0,1,1,1,1,1,0,1,1,1,1,0,1,0,1,1,1,1,1,0,0,0}
Returns: 0
".9770834613544116967"
{1,0,0,0,1,0,0,1,0,0,1,1,0,1,1,0,1,0,1,0,0,0,1,1,0,1,1,1,1,0,1,0,1,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1}
Returns: 0
".3467688854738100119"
{1,1,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,0,1,1,1}
Returns: 0
".6861591771513700436"
{1,1,1,0,1,0,0,1,0,0,0,1,0,0,1,0,1,1,1,1,1,1,1,0,1,1,0,0,1,0,0,0,0,1,1,0,0,1,1,0,1,0,1,1,0,0,1,0,1,1}
Returns: 0
".3496570116362109803"
{1,1,0,0,0,1,0,0,0,1,1,0,0,0,0,1,0,1,0,0,0,1,0,0,1,1,1,1,0,0,0,1,0,1,0,0,1,0,0,0,0,1,1,0,0,0,1,1,1,1}
Returns: 0
".9097979485765660094"
{1,0,1,1,0,1,1,1,1,0,0,1,1,0,1,1,0,0,0,0,1,1,0,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,1,1,1}
Returns: 0