Beispiel #1
0
 /**
  * Filter non-primes
  *
  * @param numbers
  */
 private ATermList filterNonPrimes(ATermList numbers) {
   ATermList primes = factory.makeList();
   numbers = numbers.getNext();
   while (!numbers.isEmpty()) {
     ATermInt prime = (ATermInt) numbers.getFirst();
     numbers = filterMultiples(prime.getInt(), numbers);
     primes = primes.append(prime);
   }
   return factory.makeList(factory.makeInt(1), primes);
 }
Beispiel #2
0
  /**
   * Filter multiples of n.
   *
   * @param n
   * @param numbers
   */
  private ATermList filterMultiples(int n, ATermList numbers) {
    int nr, len = numbers.getLength();

    for (int i = 0; i < len; i++) {
      ATermInt el = (ATermInt) numbers.elementAt(i);
      nr = el.getInt();
      if (nr % n == 0) {
        len--;
        numbers = numbers.removeElementAt(i);
      }
    }
    return numbers;
  }