Esempio n. 1
0
        public void CalculateLargestPrimeFactor()
        {
            List <double> results   = new List <double>();
            double        remainder = GoalNumber;

            // Process
            NumericSources.YieldNextPrime().TakeWhile(x => ProcessNumber(x) && x < remainder / 2).ToList();

            // Potentially recursively check a single number if it's a factor
            bool ProcessNumber(double i)
            {
                while (IsFactor(i))
                {
                    AdjustRemainder(i);
                    results.Add(i);

                    // Once the remainder is a prime, stop.
                    if (PrimeUtility.IsNumberPrime(remainder))
                    {
                        results.Add(remainder);
                        MaxPrimeOrFactor = remainder;
                        return(false);
                    }
                }

                return(true);
            }

            bool IsFactor(double i) => remainder % i == 0;
            void AdjustRemainder(double i) => remainder = remainder / i;
        }
Esempio n. 2
0
 public void Calculate()
 {
     this.ThePrimeNumberItself = NumericSources.YieldNextPrime().Skip((int)NumberOfPrime - 1).First();
 }
Esempio n. 3
0
 public void CalculateSLOW()
 {
     this.Result = NumericSources.YieldNextPrime().TakeWhile(x => x < MaxNumber).Sum();
 }