/** * 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); }
/** * Generate a list of consecutive numbers. * * @param max */ private ATermList generateNumbers(int max) { ATermList numbers = factory.makeList(); for (int i = max; i > 0; i--) numbers = factory.makeList(factory.makeInt(i), numbers); return numbers; }
public void test1() { assertTrue(getPrimes(30) == factory.parse("[1,2,3,5,7,11,13,17,19,23,29]")); assertTrue(getPrimes(500).getLength() == 96); }