void EXParser::priorityFormulaLoop(std::string &_expression) { size_t pos; for(EXFormulaSet::iterator foiter = formulas.begin(); foiter!=formulas.end(); ++foiter){ while((pos=_expression.find(foiter->first, 0))!=std::string::npos){ evaluateFormula(_expression, pos+foiter->first.length(), foiter); } } }
int main() { // Get all the primes below the coefficient limit (1000) int numPrimes = 0, *primes; getPrimesBelowLimit(&primes, &numPrimes); int a, b, i, j, n; int maxN = 0, coeffA, coeffB; // For each possible 'a' value (from -999 to 999) for (a = -1*COEFFICIENT_LIMIT + 1; a < COEFFICIENT_LIMIT; a++) { // For each possible 'b' value (prime numbers between -1000 and 1000) // 'b' has to be a prime number 'p'; when n = 0, (0*0 + 0*a + b = p) for (i = 0; i < numPrimes; i++) { for (j = -1; j < 2; j += 2) { b = j * primes[i]; // Start at n = 0, continue to evaluate formula for increasing n // until the returned result is not prime n = 0; while ( checkIfPrime(evaluateFormula(n, a, b)) != 0 ) n++; // Update the maximum number of consecutive primes if (n > maxN) { maxN = n; coeffA = a; coeffB = b; } } } } printf("%d consecutive values of n (a=%d, b=%d)\n", maxN, coeffA, coeffB); printf("%d*%d = %d\n", coeffA, coeffB, coeffA*coeffB); }
std::string ReversePolandNotation::performCalculation(const std::string &formula) const { return evaluateFormula(parseFormula(formula)); }