/// <summary> /// Sum the digits in an integer and check that number for primeness /// </summary> /// <param name="num">The number to process</param> /// <returns>true if the sum of digits is prime, false otherwise</returns> public static bool SumOfDigitsIsPrime(long num) { string StringNum = num.ToString(); long Sum = 0; foreach (char c in StringNum) { Sum += (long)char.GetNumericValue(c); }//end foreach return(IsPrimeClass.IsPrime(Sum)); }
/// <summary> /// Count the number of integers in a list that are palindromes and both the original number and the palindrome are prime. /// </summary> /// <param name="list">The list of integers to process</param> /// <returns>the count</returns> public static int CountPalindromesWhereBothArePrime(List <long> list) { int palindromePrimeCount = 0; foreach (long num in list) { if (IsPrimeClass.IsPrime(num) == true && IsPalindromeClass.IsPalindrome(num) == true) { palindromePrimeCount++; } } return(palindromePrimeCount); }
/// <summary> /// Build a list of prime numbers. /// This method will clear the list before adding anything to it. /// </summary> /// <param name="primeNumberList">Where to build the list</param> /// <param name="length">The number of primes to be added to the list, first number must always be 2</param> /// <remarks>Matt and Ryan</remarks> public static void BuildPrimeNumberList(List <long> primeNumberList, int length) { long num = 2; int count = 0; for (int i = 0; i < length; i++) { if (IsPrimeClass.IsPrime(num) == true) { primeNumberList.Add(num); //Console.WriteLine(primeNumberList[count]); count++; } num++; } }