Problem Statement
We have a collection of watches whose hands move continuously. Create a class Synchro that contains a method resynch that is given a int[] watch telling how many minutes the hand of each watch advances in an hour and that returns the position of the minute hands (in minutes past the hour) at the first time when the minute hands all exactly agree again.
Each element of watch describes a different watch. The returned value should be a non-negative double less than 60. Ignore (or rip off!) the hour hands.
Definition
- Class:
- Synchro
- Method:
- resynch
- Parameters:
- int[]
- Returns:
- double
- Method signature:
- double resynch(int[] watch)
- (be sure your method is public)
Notes
- The returned value must be accurate to within a relative or absolute value of 1E-9.
Constraints
- watch will contain between 2 and 10 elements, inclusive.
- Each element of watch will be between 1 and 200, inclusive.
Examples
{59,59,59}
Returns: 0.0
These watches are a little slow but they stay synchronized. So the first time that the minute hands are resynchronized is arbitrarily close to 0.
{60,53}
Returns: 34.28571428571427
After 8 hours the first watch has its minute hand at 0 and the other watch has circled 7 times and has its minute hand at 4 minutes. The faster watch then catches up in 4/7 of an additional hour, and at that point both minute hands are at 34.285.
{120,40}
Returns: 30.0
The faster watch catches the slower one in 3/4 of an hour at which point they are both at the half hour position.
{200,199,198,197,196,195,194,193,192,191}
Returns: 0.0
{199,200}
Returns: 0.0
{198,77}
Returns: 38.18181818181819
{73,49}
Returns: 2.499999999999991
{81,83,41,21}
Returns: 30.0
{50,74,26,50}
Returns: 5.000000000000009
{50,74,26,50,98}
Returns: 5.000000000000009
{37,13,25}
Returns: 5.000000000000009
{61,123}
Returns: 59.03225806451613
{7,4,97,151}
Returns: 20.000000000000007
{73,95,197,97,97,73,95,197,73}
Returns: 30.0
{2, 3, 5, 7, 11, 13, 17, 19}
Returns: 0.0
{2, 3, 5, 7, 11, 13, 17, 19, 23, 29}
Returns: 0.0
{1, 2, 4, 8, 16, 32, 64, 128}
Returns: 0.0
{1, 2, 4, 8, 16, 32, 64, 128, 3, 6}
Returns: 0.0
{78, 55, 66}
Returns: 0.0
{2, 69, 115}
Returns: 0.0
{179, 165, 131, 68, 128, 10, 183}
Returns: 0.0
{140, 25, 196, 100, 44, 114, 102}
Returns: 0.0
{17, 38}
Returns: 48.57142857142857
{82, 187}
Returns: 46.857142857142854
{91, 163, 126, 171, 142}
Returns: 0.0
{187, 181, 74, 152, 46}
Returns: 0.0
{22, 170, 62, 107, 85, 12, 137}
Returns: 0.0
{158, 88, 100, 176, 179, 56, 93}
Returns: 0.0
{19, 171, 166, 95, 125, 79, 93}
Returns: 0.0
{104, 176, 126, 124, 48, 135, 51}
Returns: 0.0
{141, 82, 77, 117, 98, 114, 1, 126, 63, 68}
Returns: 0.0
{92, 69, 193, 179, 57, 64, 70, 15, 112, 110}
Returns: 0.0
{114, 8, 25, 114}
Returns: 0.0
{71, 79, 188, 170, 23, 147, 75, 196, 64, 80}
Returns: 0.0
{61, 126, 173, 113, 17, 83, 54, 112, 76, 184}
Returns: 0.0
{78, 147}
Returns: 7.826086956521734
{40, 55}
Returns: 39.99999999999999
{187, 135, 157, 56, 76, 179, 174, 83, 86}
Returns: 0.0
{184, 46, 86, 34, 172, 27, 119, 84, 67}
Returns: 0.0
{198, 104, 147, 25}
Returns: 0.0
{45, 194, 57, 80}
Returns: 0.0
{154, 14}
Returns: 6.000000000000005
{96, 103}
Returns: 42.85714285714292
{149, 79, 113, 37, 86, 185, 164, 42, 176, 82}
Returns: 0.0
{66, 44, 130, 140, 93, 57, 163, 43, 111, 60}
Returns: 0.0
{77, 195, 159}
Returns: 30.0
{136, 150, 56}
Returns: 0.0
{46, 106}
Returns: 46.0