// CreatePrimeArray will return a Token of TokenType.Vector containing first 'n' primes // implemented by c0dejunkie, refined by Kashif Imran public static Token CreatePrimesArray3(string operation, List <Token> arguments) { if (arguments.Count != 1 || arguments[0].TokenType != TokenType.Vector || arguments[0].Count != 1 || arguments[0].FirstValue < 1 || arguments[0].FirstValue != (int)arguments[0].FirstValue) { return(Token.Error("Invalid argument to function. Please provide a positive integer")); } int numPrimes = (int)arguments[0].FirstValue; double[] primes = new double[numPrimes]; int count = 0; long i = 2; List <Token> args = new List <Token>(); Token number = new Token(TokenType.Vector, i); args.Add(number); while (count < numPrimes) { if (Numerical.IsPrime("", args).FirstValue != 0) { primes[count] = i; count++; } number[0] = ++i; } return(new Token(TokenType.Vector, primes)); }
public static Token CreatePrimesArray2(string operation, List <Token> arguments) { if (arguments.Count != 1 || arguments[0].TokenType != TokenType.Vector || arguments[0].Count != 1 || arguments[0].FirstValue < 1 || arguments[0].FirstValue != (int)arguments[0].FirstValue) { return(Token.Error("Invalid argument to function. Please provide a positive integer")); } int numPrimes = (int)arguments[0].FirstValue; double[] primes = new double[numPrimes]; Token primeIndxN = new Token(TokenType.Vector, 0); List <Token> primeL = new List <Token>(); primeL.Add(primeIndxN); for (int i = 0; i < numPrimes; i++) { primeIndxN[0] = i + 1; primes[i] = Numerical.FindPrimeAt("", primeL)[0]; } return(new Token(TokenType.Vector, primes)); }
static Function() { try { ArrayManipulator.CreateFunctions(); BasicCalculations.CreateFunctions(); LogsAndPowers.CreateFunctions(); Numerical.CreateFunctions(); Statistics.CreateFunctions(); Trigonometry.CreateFunctions(); Booleans.CreateFunctions(); Miscellaneous.CreateFunctions(); Matrix.CreateFunctions(); Testbed.CreateFunctions(); Directive.CreateFunctions(); Plot.CreateFunctions(); Text.CreateFunctions(); } catch //(TypeInitializationException) { //MessageBox.Show("Initialization error. Please restart the application \r\n" + e.Message); } }
// FindPrimeAt will return a Token of TokenType.Vector which will indicate the prime at a given index // Originally implemented by c0dejunkie, refined by KashifImran public static Token FindPrimeAt2(string operation, List <Token> arguments) { if (arguments.Count != 1 || arguments[0].TokenType != TokenType.Vector || arguments[0].Count != 1 || arguments[0].FirstValue < 1 || arguments[0].FirstValue != (int)arguments[0].FirstValue) { return(Token.Error("Invalid argument to function. Please provide a positive integer")); } // an index of 1 will return 2 as the prime number int primeIndex = (int)arguments[0].FirstValue; int primeCount = 0; double primeAt = 1; if (primeIndex == 1) { primeAt = 2; } else { primeCount = 1; List <Token> testL = new List <Token>(); Token primeTest = new Token(TokenType.Vector, 0); Token primeResult = new Token(TokenType.Bool, 0); testL.Add(primeTest); while (primeCount < primeIndex) { primeAt += 2; primeTest[0] = primeAt; if (Numerical.IsPrime("isprime", testL)[0] == 1) { primeCount++; } } } return(new Token(TokenType.Vector, primeAt)); }