Exemplo n.º 1
0
 // To add/remove operators change evaluateOperator() and registration
 public double evaluateOperator(double lft, char opr, double rgt) {
   switch (opr) {
     case '=':
       return rgt; // simple assignment, used as the final operation, must be maximum precedence
     case '^':
       return Math.pow(lft, rgt); // power
     case '±':
       return -rgt; // unary negation
     case '*':
       return lft * rgt; // multiply (classical)
     case '×':
       return lft * rgt; // multiply (because it's a Unicode world out there)
     case '·':
       return lft * rgt; // multiply (because it's a Unicode world out there)
     case '(':
       return lft * rgt; // multiply (implicit due to brackets, e.g "(a)(b)")
     case '/':
       return lft / rgt; // divide (classical computing)
     case '÷':
       return lft / rgt; // divide (because it's a Unicode world out there)
     case '%':
       return lft % rgt; // remainder
     case '+':
       return lft + rgt; // add/unary-positive
     case '-':
       return lft - rgt; // subtract/unary-negative
     default:
       throw new UnsupportedOperationException(
           "MathEval internal operator setup is incorrect - internal operator \""
               + opr
               + "\" not handled");
   }
 }
Exemplo n.º 2
0
 static double[] PDF() {
   double normal[] = new double[256];
   for (int x = 0; x < 256; x++) {
     float sigma = 50;
     float m = 128;
     double sigmasqr2pi = sigma * Math.sqrt(2 * Math.PI);
     float twosigma2 = 2 * sigma * sigma;
     normal[x] = Math.exp(-(Math.pow((x - m), 2)) / twosigma2) / (sigmasqr2pi);
   }
   return normal;
 }
Exemplo n.º 3
0
 public static void printer(int a, int b, int n) {
   String result = "";
   int exp = 0;
   int prev = a;
   while (exp < n) {
     prev += (Math.pow(2, exp) * b);
     result = result + prev + " ";
     exp++;
   }
   System.out.println(result.trim());
 }
Exemplo n.º 4
0
 private double evaluateAt(double a[], int start, double where) {
   int deg = a.length - 1;
   if (Math.abs(where) <= 1.0) {
     double result = a[deg];
     for (int i = deg - 2; i >= start; i--) result = result * where + a[i];
     return result;
   } else {
     double result = a[0 + start];
     for (int i = 1 + start; i < deg; i++) result = result / where + a[i];
     return result * Math.pow(where, deg - start);
   }
 }
Exemplo n.º 5
0
 public static void main(String[] args) throws IOException {
   Scanner scanner = new Scanner(new BufferedInputStream(System.in));
   while (scanner.hasNextLine()) {
     String str = scanner.nextLine();
     if (str.equals("0")) break;
     String s[] = str.split(" ");
     int sum = 1;
     for (int i = 0; i < s.length; i += 2)
       sum = sum * (int) Math.pow(Integer.parseInt(s[i]), Integer.parseInt(s[i + 1]));
     Factorization f = new Factorization();
     System.out.println(f.answer(sum - 1));
   }
 }
 public double nextDouble() {
   int c = read();
   while (isSpaceChar(c)) c = read();
   int sgn = 1;
   if (c == '-') {
     sgn = -1;
     c = read();
   }
   double res = 0;
   while (!isSpaceChar(c) && c != '.') {
     if (c == 'e' || c == 'E') {
       return res * Math.pow(10, nextInt());
     }
     if (c < '0' || c > '9') {
       throw new InputMismatchException();
     }
     res *= 10;
     res += c - '0';
     c = read();
   }
   if (c == '.') {
     c = read();
     double m = 1;
     while (!isSpaceChar(c)) {
       if (c == 'e' || c == 'E') {
         return res * Math.pow(10, nextInt());
       }
       if (c < '0' || c > '9') {
         throw new InputMismatchException();
       }
       m /= 10;
       res += (c - '0') * m;
       c = read();
     }
   }
   return res * sgn;
 }
  public static void calculateResult(int a, int b, int N) {

    // System.out.println("a: "+a+" b: "+b+" N: "+N);
    for (int i = 1; i <= N; i++) {
      //  loop N times
      int calcB = 0;
      for (int j = 0; j < i; j++) {
        calcB += (int) Math.pow(2, j) * b;
        // System.out.println("j: "+j+" calcB: "+calcB);
      }
      int result = a + calcB;
      System.out.print(result + " ");
    }
    System.out.println();
  }
Exemplo n.º 8
0
  public static void main(String[] args) throws IOException {

    Scanner scanner = new Scanner(new BufferedInputStream(System.in));
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    while (scanner.hasNext()) {
      String str = scanner.next();
      if (str.equals("0")) break;
      Long sum = 0L;

      for (int i = str.length() - 1, j = 1; i >= 0; i--, j++) {
        sum = sum + ((long) Math.pow(2, j) - 1) * ((long) str.charAt(i) - 48);
      }
      System.out.println(sum);
    }
  }
Exemplo n.º 9
0
 public void makeRelationsButtonActionPerformed(ActionEvent evt) {
   System.out.println("In make relationships");
   int k = stakeholders.size();
   for (Iterator<Stakeholder> s = stakeholders.iterator(); s.hasNext(); ) {
     Stakeholder stakeholder = s.next();
     int place = (int) Math.pow(2.0, (double) k);
     int random = (int) (Math.random() * place);
     place /= 2;
     System.out.println(random);
     for (int i = k - 1; i >= 0; i--) {
       System.out.printf("if(%d >= %d)\n", random, place);
       if (random >= place) {
         System.out.printf("%s.addI(%s)%n", stakeholder.getName(), stakeholders.get(i).getName());
         stakeholder.addInfluence(stakeholders.get(i).getName(), (int) (Math.random() * 4));
         random -= place;
       }
       place /= 2;
     }
   }
 }
Exemplo n.º 10
0
 public static void main(String[] args) throws NumberFormatException, IOException {
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int M = sc.nextInt();
   int maxValue = (int) Math.pow(2, 5) - 1;
   int[] array = new int[N];
   int first = 0;
   int second = 0;
   for (int i = 0; i < N; i++) {
     array[i] = Integer.parseInt(sc.next(), 2);
   }
   for (int i = 0; i < array.length; i++) {
     for (int j = i + 1; j < array.length; j++) {
       int or = (array[i] | array[j]);
       if (or > first) {
         first = or;
       }
     }
   }
   System.out.println(first + " " + second);
 }
Exemplo n.º 11
0
 @Override
 public Integer apply(Integer first, Integer second) {
   // System.out.println(Math.pow(first.intValue(),second.intValue()));
   return new Integer((int) Math.pow(first.intValue(), second.intValue()));
 }