static String isitpossible(int a, int b, int c, int d) {
    Pair source = new Pair(a, b);
    Pair dest = new Pair(c, d);
    list.add(source);
    while (!list.isEmpty()) {
      Pair pair = list.poll();
      if (pair.getX() == dest.getX() && pair.getY() == dest.getY()) return "Yes";
      else {
        int sum = pair.getX() + pair.getY();
        if (sum <= Math.max(c, d)) {
          list.add(new Pair(sum, pair.getY()));
          list.add(new Pair(pair.getX(), sum));
        }
      }
    }

    return "No";
  }
Example #2
0
 public synchronized Pair getPair() {
   // Make a copy to keep the original safe:
   return new Pair(p.getX(), p.getY());
 }