Example #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;
        }
Example #2
0
 public static int GetDaysBetween(DateTime start, DateTime end)
 {
     return(NumericSources.YieldSequenceFromTo(start.Year, end.Year).ToList().SelectWithBorderCases(
                x => GetDaysInFullYear(x),
                x => start.DayOfYear,
                x => end.DayOfYear).Sum());
 }
Example #3
0
        public void CalculateSmallestMultiple()
        {
            var    autod  = new AutoDictionary <double>();
            double result = 1;

            // for the sequence from 1-to-Input, get prime factors for each and store new ones (or higher powers)
            // Then get all factors and multiply them

            // Back then I didn't know IEnumerable.Range o.o
            NumericSources.YieldSequenceFromTo(1, Input).ForEach(x => autod.RegisterIfNew(x.GetPrimeFactors()));
            autod.Dictionary.ForEach(x => result *= Math.Pow(x.Key, x.Value));

            this.SmallestMultiple = result;
        }
Example #4
0
 public void GetEvenFiboSum()
 {
     EvenFiboSum = NumericSources.Fibonacci().TakeWhile(x => x < this.MaxNumber)
                   .Where(x => x % 2L == 0L)
                   .Sum();
 }
Example #5
0
 public void Calculate()
 {
     this.ThePrimeNumberItself = NumericSources.YieldNextPrime().Skip((int)NumberOfPrime - 1).First();
 }
Example #6
0
 public void GetLargestPalindrome()
 {
     Result = NumericSources.YieldPalindromesDescending(999)
              .SkipWhile(x => !this.IsCreatedWithTwoFactorsOfMaxLength(x, 999))
              .First().ToString();
 }
Example #7
0
 public void Calculate()
 {
     this.SumOfSquares1 = NumericSources.YieldSequenceFromTo(1, InputCount).Select(x => x * x).Sum();
     this.SquareOfSums2 = Math.Pow(NumericSources.YieldSequenceFromTo(1, InputCount).Sum(), 2);
     DifferenceResult   = SquareOfSums2 - SumOfSquares1;
 }
Example #8
0
 public void Calculate()
 {
     this.Result = NumericSources.YieldTriangleNumbers()
                   .FirstOrDefault(x => ProbabilityUtility.GetAllCombinationsProducts(x.GetPrimeFactors().ProcessList(this.LogList)) > DivisorCount);
 }
Example #9
0
 public void CalculateSLOW()
 {
     this.Result = NumericSources.YieldNextPrime().TakeWhile(x => x < MaxNumber).Sum();
 }