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; }
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()); }
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; }
public void GetEvenFiboSum() { EvenFiboSum = NumericSources.Fibonacci().TakeWhile(x => x < this.MaxNumber) .Where(x => x % 2L == 0L) .Sum(); }
public void Calculate() { this.ThePrimeNumberItself = NumericSources.YieldNextPrime().Skip((int)NumberOfPrime - 1).First(); }
public void GetLargestPalindrome() { Result = NumericSources.YieldPalindromesDescending(999) .SkipWhile(x => !this.IsCreatedWithTwoFactorsOfMaxLength(x, 999)) .First().ToString(); }
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; }
public void Calculate() { this.Result = NumericSources.YieldTriangleNumbers() .FirstOrDefault(x => ProbabilityUtility.GetAllCombinationsProducts(x.GetPrimeFactors().ProcessList(this.LogList)) > DivisorCount); }
public void CalculateSLOW() { this.Result = NumericSources.YieldNextPrime().TakeWhile(x => x < MaxNumber).Sum(); }