示例#1
0
        public void ShouldFindProductOfAAndB(int[] expected, int sum)
        {
            var sut = new PythagoreanTripletFinder();
            var actual = sut.GetTriplets(sum);

            Assert.Equal(expected, actual);
        }
示例#2
0
文件: Program.cs 项目: Jaxwood/euler
        static void Main(string[] args)
        {
            var nat = new NaturalNumberCalculator();
            System.Console.WriteLine(
                "The sum of natural number between 1 1000 is {0}",
                nat.GetAllNumbers(
                    new int[] { 3, 5 },
                    Enumerable.Range(1, 999).ToArray()
                ).Sum());

            var fib = new Fibonacci();
            var fibSumSpec = new FibonacciSumSpecification(4000000);
            fib.GetUntil(fibSumSpec);
            System.Console.WriteLine(
                "Fibonacci whose values do not exceed four million - the sum of even valued terms: {0}",
                fibSumSpec.Result);

            var primeFactorFinder = new PrimeFactorFinder(new PrimeUtil());
            System.Console.WriteLine(
                "The largest prime factor of the number 600851475143 is {0}",
                primeFactorFinder.GetPrimeFactors(600851475143).Max());

            var palindromeFinder = new PalindromeFinder(new MathUtil());
            System.Console.WriteLine(
                "Largest paldindrome of the product of two 3 digits numbers is {0}",
                palindromeFinder.GetLargestPalindrome(3));

            var lowestDividableNumberFinder = new LowestDividableNumberFinder();
            System.Console.WriteLine(
                "Smallest positive number that is evenly divisible by all of the numbers from 1 to 20 is {0}",
                lowestDividableNumberFinder.GetLowestNumberDividableWith(Enumerable.Range(1, 20).ToArray()));

            var sumOfSquaresCalculator = new SumOfSquaresCalculator();
            System.Console.WriteLine(
                "The difference between the sum of the squares of the first one hundred natural numbers and the square of the sum is {0}",
                sumOfSquaresCalculator.GetSum(Enumerable.Range(1, 100).ToArray()));

            var primeGenerator = new PrimeGenerator(new PrimeUtil());
            System.Console.WriteLine(
                "The 10001 prime is {0}",
                primeGenerator.GetPrimes(10001).Last());

            var largestProductFinder = new LargestProductFinder(5);
            System.Console.WriteLine(
                "The largest product in the series is {0}",
                largestProductFinder.GetLargestProduct("7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"));

            var pythagoreanTripletFinder = new PythagoreanTripletFinder();
            System.Console.WriteLine(
                "The product of a, b and c where the sum is 1000 is {0}",
                pythagoreanTripletFinder.GetTriplets(1000).Aggregate(1, (a, c) => a *= c));

            var primeFinder = new PrimeFinder(new PrimeUtil());
            System.Console.WriteLine(
                "The sum of all primes below 2000000 is {0}",
                primeFinder.GetSumOfPrimes(2000000));

            var gridProductFinder = new GridProductFinder(4);
            System.Console.WriteLine(
                "Greatest adjacent product in grid is {0}",
                gridProductFinder.GetProduct(GetGrid()));

            var triangularNumber = new TriangularNumber(new PrimeFactorFinder(new PrimeUtil()));
            System.Console.WriteLine(
                "Lowest triangular number with 500 divisors is {0}",
                triangularNumber.GetLowestTriangularNumber(500));

            var sumDigitProcessor = new SumDigitProcessor(50);
            System.Console.WriteLine(
                "Sum all 50 digits number is {0}",
                sumDigitProcessor.Sum(GetInput()));

            var collatzTermsFinder = new CollatzTermsFinder();
            System.Console.WriteLine(
                "Largest number with most term below 1.000.000 is {0}",
                collatzTermsFinder.GetLargestTermBelowNumber(Convert.ToInt32(Math.Pow(10, 6))));

            var lattice = new Lattice();
            System.Console.WriteLine(
                "Number of path through 20 x 20 grid is {0}",
                lattice.GetPaths(20, 20));

            var sumOfPow = new SumOfPow(2);
            System.Console.WriteLine(
                "The sum of digits of 2^1000 is {0}",
                sumOfPow.GetSum(1000));

            var numberCounter = new NumberCounter(new NumberToLetter());
            System.Console.WriteLine(
                "Number of letter from 1-1000 is {0}",
                numberCounter.GetTextCount(1, 1000));

            var maximumPathFinder = new MaximumPathFinder();
            System.Console.WriteLine(
                "The maximum path of triangle is {0}",
                maximumPathFinder.GetMax(GetTriangleData()));

            var dateFinder = new DateFinder();
            System.Console.WriteLine(
                "No of Sundays is {0}",
                dateFinder.GetMonthsWithDay(DateTime.Parse("1901-01-01"), DateTime.Parse("2000-12-31"), DayOfWeek.Sunday));

            var factorialSumFinder = new FactorialSumFinder();
            System.Console.WriteLine(
                "The sum of the digits of 100! is {0}",
                factorialSumFinder.GetFactorialSum(100));

            var amicableNumbers = new AmicableNumberFinder(new MathUtil());
            System.Console.WriteLine(
                "The sum of all amicable numbers below 10000 is {0}",
                Enumerable.Range(1, 10000).Where(c => amicableNumbers.IsAmicableNumber(c)).Sum());

            var numberScorer = new NumberScorer(GetNames());
            System.Console.WriteLine(
                "The sum of all amicable numbers below 10000 is {0}",
                numberScorer.ScoreNames());

            var abundantSum = new AbundantSum(new MathUtil());
            System.Console.WriteLine(
                "The sum of positive integers that is not a sum of abundant numbers is {0}",
                abundantSum.GetSumOfIntegersThatIsNotSumOfAbundantNumbers(28123));

            var lexicographicPermutation = new LexicographicPermutation(new MathUtil());
            System.Console.WriteLine(
                "The millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 is {0}",
                lexicographicPermutation.GetPermutation(1234567890, 1000000));

            var fibnacci = new Fibonacci();
            System.Console.WriteLine(
                "The first term in the Fibonacci sequence to contain 1000 digits is {0}",
                fibnacci.GetUntil(new DigitSpecification(1000)));

            var reciprocal = new ReciprocalCycle(new PrimeFactorFinder(new PrimeUtil()));
            System.Console.WriteLine(
                "The value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part is {0}",
                reciprocal.GetLargestRecurring(1000));

            var quadraticPrime = new QuadraticPrime(new PrimeUtil());
            System.Console.WriteLine(
                "The product of the coefficients, a and b, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n = 0 is {0}",
                quadraticPrime.GetProduct(-1000, 2001, -1000, 2001));

            var numberSpiralDiagonal = new NumberSpiralDiagonal();
            System.Console.WriteLine(
                "The sum of the numbers on the diagonals in a 1001 by 1001 spiral form is {0}",
                numberSpiralDiagonal.GetDiagonalSum(1001));

            var distinctPower = new DistinctPower();
            System.Console.WriteLine(
                "The distinct terms for the sequence generated by a^b for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100 is {0}",
                distinctPower.GetNumberOfTerms(2, 100));

            var digitPowerFinder = new DigitPowerFinder(new MathUtil());
            System.Console.WriteLine(
                "The sum of all the numbers that can be written as the sum of fifth powers of their digits is {0}",
                digitPowerFinder.GetSum(5));

            System.Console.ReadLine();
        }