Exemplo n.º 1
1
  public int count(int b1, int q1, int n1, int b2, int q2, int n2) {
    if (b2 == 0 || q2 <= 1) {
      int tb = b1;
      int tq = q1;
      int tn = n1;
      b1 = b2;
      q1 = q2;
      n1 = n2;
      b2 = tb;
      q2 = tq;
      n2 = tn;
    }

    if (b1 == 0 || q1 <= 1) {
      HashSet<Integer> set = new HashSet<Integer>();
      set.add(b1);
      if (n1 > 1) {
        set.add(b1 * q1);
      }

      long curr = b2;
      for (int i = 0; i < n2; i++) {
        set.add((int) curr);
        curr *= q2;
        if (curr > 500000000) {
          return (n2 - i - 1) + set.size();
        }
      }

      return set.size();
    } else {
      HashSet<String> set = new HashSet<String>();

      int factors[] = findFactors(b1, q1, b2, q2);
      int repb1[] = decompose(b1, factors);
      int repb2[] = decompose(b2, factors);
      int repq1[] = decompose(q1, factors);
      int repq2[] = decompose(q2, factors);

      for (int i = 0; i < n1; i++) {
        set.add(Arrays.toString(repb1));
        for (int j = 0; j < repb1.length; j++) {
          repb1[j] += repq1[j];
        }
      }

      for (int i = 0; i < n2; i++) {
        set.add(Arrays.toString(repb2));
        for (int j = 0; j < repb2.length; j++) {
          repb2[j] += repq2[j];
        }
      }

      return set.size();
    }
  }
  /** {@inheritDoc} */
  @Override
  public Object onReceive(@Nullable Object obj) {
    if (obj instanceof byte[]) {
      X.println(">>> Byte array received over REST: " + Arrays.toString((byte[]) obj));

      BigInteger val = new BigInteger((byte[]) obj);

      X.println(">>> Unpacked a BigInteger from byte array received over REST: " + val);

      return val;
    } else return obj;
  }
  /** {@inheritDoc} */
  @Override
  public Object onSend(Object obj) {
    if (obj instanceof BigInteger) {
      X.println(">>> Creating byte array from BigInteger to send over REST: " + obj);

      byte[] bytes = ((BigInteger) obj).toByteArray();

      X.println(
          ">>> Created byte array from BigInteger to send over REST: " + Arrays.toString(bytes));

      return bytes;
    } else return obj;
  }
Exemplo n.º 4
0
  @Override
  public String toString() {
    switch (this.type) {
      case OPERATOR:
      case OPENING_BRACKET:
      case CLOSING_BRACKET:
        return Character.toString(operator);

      case FUNCTION:
        return this.function;

      case VALUE:
      default:
        return Arrays.toString(value);
    }
  }
 private InputStream getReport(
     HttpServletRequest request,
     HttpServletResponse response,
     Tab tab,
     TableModel tableModel,
     Integer columnCountLimit)
     throws ServletException, IOException {
   StringBuffer suri = new StringBuffer();
   suri.append("/xava/jasperReport");
   suri.append("?language=");
   suri.append(Locales.getCurrent().getLanguage());
   suri.append("&widths=");
   suri.append(Arrays.toString(getWidths(tableModel)));
   if (columnCountLimit != null) {
     suri.append("&columnCountLimit=");
     suri.append(columnCountLimit);
   }
   response.setCharacterEncoding(XSystem.getEncoding());
   return Servlets.getURIAsStream(request, response, suri.toString());
 }
  public double calc(int[] hand, int[] sothe) {
    double ret = 0;
    int len = hand.length;
    boolean[] used = new boolean[len];

    // fill the solid
    for (int i = 0; i < len; i++) {
      if (sothe[i] == -1) continue;

      // pick lowest winner
      int min = INF;
      int pos = -1;
      for (int j = 0; j < len; j++) {
        if (hand[j] > sothe[i] && !used[j] && hand[j] < min) {
          min = hand[j];
          pos = j;
        }
      }
      if (min != INF) {
        used[pos] = true;
        ret += 1;
        continue;
      }

      // pick lowest loser
      min = INF;
      pos = -1;
      for (int j = 0; j < len; j++) {
        if (!used[j] && hand[j] < min) {
          min = hand[j];
          pos = j;
        }
      }
      used[pos] = true;
    }
    System.out.println(Arrays.toString(used));

    // get the -1 hands
    List<Integer> sotheHands = new ArrayList<>();
    for (int i = 1; i <= 2 * len; i++) {
      boolean appears = false;
      for (int j = 0; j < len; j++) {
        if (hand[j] == i || sothe[j] == i) {
          appears = true;
          break;
        }
      }
      if (!appears) sotheHands.add(i);
    }

    // calculate the unknown
    for (int sotheHand : sotheHands) {
      int wincount = 0;
      int losecount = 0;
      for (int j = 0; j < len; j++) {
        if (used[j]) continue;
        if (sotheHand > hand[j]) {
          losecount++;
        } else {
          wincount++;
        }
      }
      if (wincount + losecount != 0) {
        ret += (double) wincount / (double) (wincount + losecount);
      }
    }

    return ret;
  }