Ejemplo n.º 1
0
        public void IndexInSequence_InvalidNthTerm2()
        {
            var problem = new Problem1();

            var result = problem.IndexInSequence(1, -2);

            Assert.Fail();
        }
Ejemplo n.º 2
0
        public void IndexInSequence_InvalidMultiplier2()
        {
            var problem = new Problem1();

            var result = problem.IndexInSequence(-10, 3);

            Assert.Fail();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Problem1 prog = new Problem1();
            int      sum  = prog.sumOfMultiples(new int[] { 3, 5 }, 10);

            Console.WriteLine("The sum of all positives multiples of 3 and 5 below 1000:   " + sum);
            Console.ReadKey();
        }
Ejemplo n.º 4
0
        public void IndexInSequence_1stTerm()
        {
            var problem = new Problem1();

            var result = problem.IndexInSequence(4, 4);

            Assert.AreEqual(1, result);
        }
Ejemplo n.º 5
0
        public void IndexInSequence_2ndTerm()
        {
            var problem = new Problem1();

            var result = problem.IndexInSequence(4, 8);

            Assert.AreEqual(2, result);
        }
Ejemplo n.º 6
0
        public void IndexInSequence_After3rdTermBefore4th()
        {
            var problem = new Problem1();

            var result = problem.IndexInSequence(4, 13);

            Assert.AreEqual(3, result);
        }
Ejemplo n.º 7
0
        public static void Solve(Problem1 problem)
        {
            uint answer = 0;

            for (int i = problem.RangeStart.Value; i < problem.RangeEnd.Value; i++)
            {
                if (i % problem.Multiple1.Value == 0 || i % problem.Multiple2.Value == 0)
                {
                    answer += (uint)i;
                }
            }

            problem.Answer = answer;
        }
Ejemplo n.º 8
0
 public static void DisplayProblem(Problem1 problem)
 {
     Console.WriteLine("Project Euler Problem #" + problem.Number);
     Console.WriteLine(problem.Name);
     Console.Write(Environment.NewLine);
     Console.WriteLine(problem.RangeStart.Name + ": " + problem.RangeStart.Value);
     Console.WriteLine(problem.RangeEnd.Name + ": " + problem.RangeEnd.Value);
     Console.Write(Environment.NewLine);
     Console.WriteLine(problem.Multiple1.Name + ": " + problem.Multiple1.Value);
     Console.WriteLine(problem.Multiple2.Name + ": " + problem.Multiple2.Value);
     Console.Write(Environment.NewLine);
     Console.WriteLine("Answer : " + problem.Answer);
     Console.Write(Environment.NewLine);
 }
Ejemplo n.º 9
0
        public void Problem1_Can_Solve()
        {
            // Arrange
            const int expected = 233168;
            var target = new Problem1();

            // Act
            var result = target.Solve();
            var iterativeResult = ImperativeSolution();
            var functionalResult = FunctionalSolution();

            // Assert
            Assert.AreEqual(expected, result);
            Assert.AreEqual(expected, iterativeResult);
            Assert.AreEqual(expected, functionalResult);
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            int answer;

            Console.WriteLine("Project Euler - Problem 1");
            Problem1 problem1 = new Problem1();

            problem1.Solve();
            Console.ReadKey();


            Console.WriteLine("Project Euler - Problem 2");
            Problem2.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 3");
            Problem3.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 4");
            Problem4.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 5");
            Problem5.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 6");
            Problem6.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 7");
            Problem7.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 8");
            Problem8.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 9");
            Problem9.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 10");
            Problem10.Solve();
            Console.ReadKey();
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            int answer;
            Console.WriteLine("Project Euler - Problem 1");
            Problem1 problem1 = new Problem1();
            problem1.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 2");
            Problem2.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 3");
            Problem3.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 4");
            Problem4.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 5");
            Problem5.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 6");
            Problem6.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 7");
            Problem7.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 8");
            Problem8.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 9");
            Problem9.Solve();
            Console.ReadKey();

            Console.WriteLine("Project Euler - Problem 10");
            Problem10.Solve();
            Console.ReadKey();
        }
Ejemplo n.º 12
0
        public void Run()
        {
            Problem1 problem = new Problem1(1, "Sum of Multiples");

            // Range Start
            Output.Clear();
            Output.DisplayProblem(problem);
            PromptFor(problem.RangeStart.Name);
            problem.RangeStart.Value = Converter.ConvertStringToInt(Input.InputString());

            // Range End
            Output.Clear();
            Output.DisplayProblem(problem);
            PromptFor(problem.RangeEnd.Name);
            problem.RangeEnd.Value = Converter.ConvertStringToInt(Input.InputString());

            // Multiple 1
            Output.Clear();
            Output.DisplayProblem(problem);
            PromptFor(problem.Multiple1.Name);
            problem.Multiple1.Value = Converter.ConvertStringToInt(Input.InputString());

            // Multiple2
            Output.Clear();
            Output.DisplayProblem(problem);
            PromptFor(problem.Multiple2.Name);
            problem.Multiple2.Value = Converter.ConvertStringToInt(Input.InputString());

            if (Generalvalidator.Validate(problem))
            {
                if (SpecificValidator.SpecificValidate(problem))
                {
                    Problem1Solver.Solve(problem);
                }
            }

            Output.Clear();
            Output.DisplayProblem(problem);
        }
Ejemplo n.º 13
0
        public static void Main(string[] args)
        {
            Console.WriteLine($"Problem1: Find the sum of all the multiples of 3 or 5 below 1000. Answer : {Problem1.Solve(3, 5, Problem1BelowValue-1)}");

            Console.WriteLine($"Problem2: By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. Answer : {Problem2.Solve(Problem2FibLimt)}");

            Console.WriteLine($"Problem3: What is the largest prime factor of the number 600851475143? Answer : {Problem3.Solve(Problem3LargestPrime)}");

            Console.WriteLine($"Problem4 :  Find the largest palindrome made from the product of two 3-digit numbers. Answer : {Problem4.Solve()}");

            Console.WriteLine($"Problem5 :  What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?. Answer : {Problem5.Solve(20)}");

            Console.WriteLine($"Problem6 :  Find the difference between the sum of the squares of the first 100 natural numbers and the square of the sum. Answer : {Problem6.Solve(100)}");

            Console.WriteLine($"Problem7 :  What is the 10 001st prime number? Answer : {Problem7.Solve1(10001)}");

            Console.WriteLine($"Problem8 :  Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product? Answer : {Problem8.Solve(13)}");
        }
Ejemplo n.º 14
0
 public static bool Validate(Problem1 problem)
 {
     return true;
 }
 public void SetUp()
 {
     problem = new Problem1();
 }
Ejemplo n.º 16
0
 public static bool SpecificValidate(Problem1 problem)
 {
     // Check the problem rules
     return true;
 }
Ejemplo n.º 17
0
 public void SumTest()
 {
     Problem1 target = new Problem1(); // TODO: Initialize to an appropriate value
     int actual;
     actual = target.Sum();
 }
Ejemplo n.º 18
0
        public void LargestNumberInSeries_After3rdTermBefore4th()
        {
            var problem = new Problem1();

            var result = problem.LargestNumberInSeries(5, 16);

            Assert.AreEqual(15, result);
        }
Ejemplo n.º 19
0
        public void LargestNumberInSeries_InvalidLimit1()
        {
            var problem = new Problem1();

            var result = problem.LargestNumberInSeries(10, 3);

            Assert.Fail();
        }
Ejemplo n.º 20
0
        public void LargestNumberInSeries_InvalidLimit2()
        {
            var problem = new Problem1();

            var result = problem.IndexInSequence(1, -2);

            Assert.Fail();
        }
Ejemplo n.º 21
0
        public void LargestNumberInSeries_2ndTerm()
        {
            var problem = new Problem1();

            var result = problem.LargestNumberInSeries(5, 10);

            Assert.AreEqual(10, result);
        }
Ejemplo n.º 22
0
        public void LargestNumberInSeries_InvalidMultiplier2()
        {
            var problem = new Problem1();

            var result = problem.LargestNumberInSeries(-9, 3);

            Assert.Fail();
        }
Ejemplo n.º 23
0
        public void SumOfMultiples_InvalidLimit2()
        {
            var problem = new Problem1();

            var result = problem.SumOfMultiples(1, 0);

            Assert.Fail();
        }
Ejemplo n.º 24
0
        public void SumOfMultiples_InvalidMultiplier2()
        {
            var problem = new Problem1();

            var result = problem.SumOfMultiples(-10, 10);

            Assert.Fail();
        }
Ejemplo n.º 25
0
        public void SumOfTwoMultiples_Answer()
        {
            var problem = new Problem1();

            var result = problem.SumOfTwoMultiples(3, 5, 999);

            Assert.AreEqual(233168, result);
        }
Ejemplo n.º 26
0
        public void SumOfMultiples_Test3()
        {
            var problem = new Problem1();

            var result = problem.SumOfMultiples(3, 10);

            Assert.AreEqual(18, result);
        }