title: How to solve Tortoise racing
body: <p>There is a problem called: Tortoise racing.</p>
  
  <p>The question is:</p>
  
  <p>Two tortoises named A and B must run a race. A starts with an average speed of 720 feet per hour. Young B knows she runs faster than A, and furthermore has not finished her cabbage.</p>
  
  <p>When she starts, at last, she can see that A has a 70 feet lead but B's speed is 850 feet per hour. How long will it take B to catch A?</p>
  
  <p>More generally: given two speeds v1 (A's speed, integer > 0) and v2 (B's speed, integer > 0) and a lead g (integer > 0) how long will it take B to catch A?</p>
  
  <p>The result will be an array [hour, min, sec] which is the time needed in hours, minutes and seconds (round down to the nearest second) or a string in some languages.</p>
  
  <blockquote>
    <p>If v1 >= v2 then return nil, nothing, null, None or {-1, -1, -1} for
    C++, C, Go, Nim, [] for Kotlin or "-1 -1 -1".</p>
  </blockquote>
  
  <p>Examples:
  (form of the result depends on the language)</p>
  
  <blockquote>
    <p>race(720, 850, 70) => [0, 32, 18] or "0 32 18"</p>
    
    <p>race(80, 91, 37)   => [3, 21, 49] or "3 21 49"</p>
  </blockquote>
  
  <p>I tried to solve it like this: </p>
  
  <pre><code>  public static int[] race(int v1, int v2, int g) {
  
              int v3 = v2 - v1;
              double time = (double )g / (double)v3;
              int result[] = new int[3];
  
              if (v2 &gt; v1) {
                  if (time &gt; 1) {
                      while (time &gt; 10) {
                          time /= 10;
                      }
                      result[0] = (int) time;
                      result[1] = (int) ((time - result[0]) * 60);
                      result[2] = (int) ((((time - result[0]) * 60) - result[1]) * 60);
                      System.out.print(result[0] + " " + result[1] + " " + result[2]);
                  } else {
                      result[0] = 0;
                      result[1] = (int) (time * 60);
                      result[2] = (int) (((time * 60) - result[1]) * 60);
                      System.out.print(result[0] + " " + result[1] + " " + result[2]);
                  }
              }
              else {
                  return null;
              }
  
              return result;
          }
  </code></pre>
  
  <p>but it keeps failing on test cases, could you please help me?</p>