Esempio n. 1
0
        static void Main(string[] args)
        {
            int i = 20;

            while (i % 2 != 0 || i % 3 != 0 || i % 4 != 0 || i % 5 != 0 ||
                   i % 6 != 0 || i % 7 != 0 || i % 8 != 0 || i % 9 != 0 ||
                   i % 10 != 0 || i % 11 != 0 || i % 12 != 0 || i % 13 != 0 ||
                   i % 14 != 0 || i % 15 != 0 || i % 16 != 0 || i % 17 != 0 ||
                   i % 18 != 0 || i % 19 != 0 || i % 20 != 0)
            {
                i += 20;
            }

            Console.WriteLine("The smallest number evenly divisible by 1 through 20 is: " + i);

            Console.WriteLine($"The solution to Q13 is {SolveQ13Euler.SolveQ13()}\n\n");

            Console.WriteLine($"Problem 1: {Problem1.solve()}");
        }
Esempio n. 2
0
        public void Answer()
        {
            var sumOfAllMultiples = new Problem1().FindSumOfMultiplesOfThreeOrFive();

            sumOfAllMultiples.ShouldBe(233168);
        }
Esempio n. 3
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Hello User!");
            bool finished = false;

            while (!finished)
            {
                bool   success = false;
                int    id      = 0;
                string input   = string.Empty;
                while (!success)
                {
                    Console.WriteLine("Which Project Euler problem would you like to see? Enter the number only, or q to quit");

                    input = Console.ReadLine();
                    if (input == "q")
                    {
                        Environment.Exit(0);
                    }

                    try
                    {
                        id      = int.Parse(input);
                        success = true;
                    }
                    catch
                    {
                        Console.WriteLine("Apologies. I don't think that was an integer. Please try again:");
                    }
                }

                IProblem problem = new Problem1();
                try
                {
                    problem = (IProblem)CreateSpecificInstance("Problem" + id.ToString());
                }
                catch
                {
                    Console.WriteLine("Apologies. I don't seem to have problem {0} in my library. I will exit this program in shame", id);
                    Environment.Exit(1);
                }

                problem.Pose();

                Console.WriteLine("Press y to see solution, q to quit, or any other key to see another problem");
                input = Console.ReadLine();

                if (input == "q")
                {
                    Environment.Exit(1);
                }

                string result;
                if (input == "y")
                {
                    Console.WriteLine("Solving...");
                    result = problem.Solve();
                    Console.WriteLine("Answer: " + result);
                }
            }
        }