示例#1
0
        public void Input1()
        {
            var root = ParseTree("*N");
            var r    = Problem4.MinCoverSet(root);

            Assert.Equal(1, r);
        }
示例#2
0
        public void Input6()
        {
            var root = ParseTree("N(*N(N,N),*N(N,N,N))(*N(N,N,N,N))(*N(N,N))(*N(N))");
            var r    = Problem4.MinCoverSet(root);

            Assert.Equal(5, r);
        }
示例#3
0
文件: code.cs 项目: ghj123h/Taicai
        public static IEnumerable <Problem> GetProblems()
        {
            List <Problem> list = new List <Problem>();
            Problem        tmp;

            // Problem 1
            tmp = new DefaultProblem("y");
            list.Add(tmp);
            // Problem 2
            tmp = new DefaultProblem("3");
            list.Add(tmp);
            // Problem 3
            tmp = new NumberProblem(10, 1.3);
            list.Add(tmp);
            // Problem 4
            tmp = new Problem4();
            list.Add(tmp);
            // Problem 5
            tmp = new NumberProblem(27.9);
            list.Add(tmp);
            // Problem 6
            tmp = new NumberProblem(19.8725);
            list.Add(tmp);
            return(list);
        }
示例#4
0
        public static IEnumerable <Problem> GetProblems()
        {
            List <Problem> list = new List <Problem>();
            Problem        tmp;

            // Problem 1
            tmp = new DefaultProblem("b");
            list.Add(tmp);
            // Problem 2
            tmp = new DefaultProblem("n");
            list.Add(tmp);
            // Problem 3
            tmp = new DefaultProblem("3");
            list.Add(tmp);
            // Problem 4
            tmp = new Problem4();
            list.Add(tmp);
            // Problem 5
            tmp = new NumberProblem(127.2);
            list.Add(tmp);
            // Problem 6
            tmp = new NumberProblem(3.495);
            list.Add(tmp);
            return(list);
        }
示例#5
0
文件: code.cs 项目: ghj123h/Taicai
        public static IEnumerable <Problem> GetProblems()
        {
            List <Problem> list = new List <Problem>();
            Problem        tmp;

            // Problem 1
            tmp = new DefaultProblem("y");
            list.Add(tmp);
            // Problem 2
            tmp = new DefaultProblem("abcdefg");
            list.Add(tmp);
            // Problem 3
            tmp = new OffsetProblem(1, 0.87);
            list.Add(tmp);
            // Problem 4
            tmp = new Problem4();
            list.Add(tmp);
            // Problem 5
            tmp = new MultipleProblem("678");
            list.Add(tmp);
            // Problem 6
            tmp = new NumberProblem(113.02, NumberProblem.ACE * 2.5);
            list.Add(tmp);
            return(list);
        }
        // GET api/problem/1
        public string Get(int id)
        {
            string result  = "";
            Solver problem = new Problem1();

            if (id == 1)
            {
                problem = new Problem1();
            }
            if (id == 2)
            {
                problem = new Problem2();
            }
            if (id == 3)
            {
                problem = new Problem3();
            }
            if (id == 4)
            {
                problem = new Problem4();
            }
            if (id == 5)
            {
                problem = new Problem5();
            }

            problem.Solve();
            return(problem.Solution);



            return(result);
        }
示例#7
0
        public void Test4()
        {
            var problem = new Problem4();
            var result  = problem.Solution1();

            Assert.Equal(906609, result);
        }
示例#8
0
        public void Input7()
        {
            var root = ParseTree("*N(N(*N(N(*N(N)(N))(*N))(N))(*N))(N)");
            var r    = Problem4.MinCoverSet(root);

            Assert.Equal(5, r);
        }
        public void IterationSetup()
        {
            var numbers = Enumerable
                          .Range(1, ElementCount)
                          .ToArray();

            _problem = new Problem4(numbers);
        }
示例#10
0
        public void Input4()
        {
            // original example
            var root = ParseTree("*N(*N(N,N),N)(N)");
            var r    = Problem4.MinCoverSet(root);

            Assert.Equal(2, r);
        }
示例#11
0
        public void SolutionsShouldMatch(int length, long expectedValue)
        {
            var problem = new Problem4();

            var result = problem.Solve(new SingleLimitProblemArgs(length));

            Assert.AreEqual(expectedValue.ToString(), result);
        }
示例#12
0
        public void CompactFindsPalindrome()
        {
            var sut = new Problem4();

            var result = sut.FindPalindrom();

            Assert.AreEqual(906609, result);
        }
示例#13
0
        public void largest3DigitPalindromeTest()
        {
            Problem4 p        = new Problem4();
            int      expected = 906609;
            int      actual   = p.largest3DigitPalindromeBrute();

            Assert.AreEqual(expected, actual);
        }
示例#14
0
        public void Passport_IsValid()
        {
            var passports = Problem4.ParseInput(FirstInput).ToList();

            Assert.IsTrue(passports[0].IsValid);
            Assert.IsFalse(passports[1].IsValid);
            Assert.IsTrue(passports[2].IsValid);
            Assert.IsFalse(passports[3].IsValid);
        }
示例#15
0
 public void TestProblem4()
 {
     Assert.AreEqual(Problem4.LargestNumber(new List <uint> {
         420, 42, 423
     }), "42423420");
     Assert.AreEqual(Problem4.LargestNumber(new List <uint> {
         50, 2, 1, 9
     }), "95021");
 }
示例#16
0
        public void SolveTest()
        {
            Problem4 problem4 = new Problem4();

            double expected = 9009;
            double actual   = problem4.Solve(2);

            Assert.AreEqual(expected, actual);
        }
示例#17
0
 static void Main(string[] args)
 {
     Console.ForegroundColor = ConsoleColor.DarkGreen;
     Console.WriteLine("Project Euler");
     Problem1.Solve();
     Problem2.Solve();
     Problem3.Solve();
     Problem4.Solve();
     Console.ReadLine();
 }
示例#18
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                return;
            }
            var p = new Problem4();

            p.Solve(args[0], args[1]);
        }
示例#19
0
 static void Main(string[] args)
 {
     Console.WriteLine($"Problem 1: {Problem1.Solve()}");
     Console.WriteLine($"Problem 2: {Problem2.Solve()}");
     Console.WriteLine($"Problem 3: {Problem3.Solve()}");
     Console.WriteLine($"Problem 4: {Problem4.Solve()}");
     Console.WriteLine($"Problem 5: {Problem5.Solve()}");
     Console.WriteLine($"Problem 6: {Problem6.Solve()}");
     Console.WriteLine($"Problem 7: {Problem7.Solve()}");
     Console.WriteLine($"Problem 8: {Problem8.Solve()}");
     Console.WriteLine($"Problem 9: {Problem9.Solve()}");
     Console.WriteLine($"Problem 10: {Problem10.Solve()}");
 }
示例#20
0
    public bool PalindromicNumber(long number)
    {
        bool     palindromic   = false;
        Problem4 reverse       = new Problem4();
        long     reverseNumber = reverse.ReverseNumber(number);

        if (number == reverseNumber)
        {
            palindromic = true;
        }

        return(palindromic);
    }
示例#21
0
        public void isPalindromeTest()
        {
            Problem4 p        = new Problem4();
            bool     expected = true;
            bool     actual   = p.isPalindrome(9009);

            Assert.AreEqual(expected, actual);

            Problem4 p1 = new Problem4();

            expected = false;
            actual   = p.isPalindrome(1100);
            Assert.AreEqual(expected, actual);
        }
示例#22
0
        public void Passport_IsStrictlyValid()
        {
            var invalidPassports = Problem4.ParseInput(InvalidInput).ToList();
            var validPassports   = Problem4.ParseInput(ValidInput).ToList();

            foreach (var invalidPassport in invalidPassports)
            {
                Assert.IsFalse(invalidPassport.IsStrictlyValid);
            }

            foreach (var validPassport in validPassports)
            {
                Assert.IsTrue(validPassport.IsStrictlyValid);
            }
        }
示例#23
0
    static void Main()
    {
        long number, largestPalindrome = 0;

        Problem4 palindrome = new Problem4();

        for (long i = 999; i > 99; i--)
        {
            for (long j = 999; j > 99; j--)
            {
                number = i * j;
                if (palindrome.PalindromicNumber(number) &&
                    number > largestPalindrome)
                {
                    largestPalindrome = number;
                }
            }
        }

        Console.WriteLine(largestPalindrome);
        Console.ReadKey();
    }
示例#24
0
 public void TestLogSorting()
 {
     Assert.AreEqual(Problem4.ParseInput(TestInputJumbled), Problem4.ParseInput(TestInput));
 }
示例#25
0
        static public void Main(string[] args)
        {
            Console.WriteLine("Console App Used to Display Results of my Euler Project Code");
            Console.WriteLine("As long as the questions are simple enough, they will all show up here.");
            Console.WriteLine("------------------------------\n");

            while (!endApp)
            {
                Console.WriteLine("Option 1: Run Problem 1.");
                Console.WriteLine("Option 2: Run Problem 2.");
                Console.WriteLine("Option 3: Run Problem 3.");
                Console.WriteLine("Option 4: Run Problem 4.");
                Console.WriteLine("Option 5: Run Problem 5.");
                Console.WriteLine("Option 6: Run Problem 6.");
                Console.WriteLine("Option 7: Run Problem 7.");
                Console.WriteLine("Option 8: Run Problem 8.");
                Console.WriteLine("Option 9: Run Problem 9.");
                Console.WriteLine("\n");


                Console.Write("Press 'n' and Enter to close the app, or press # of option and Enter to continue: ");
                string caseSwitch = Console.ReadLine();

                switch (caseSwitch)
                {
                case "1":
                    Console.WriteLine("\n\nCase 1:\n\n");
                    IProblem problem1 = new Problem1();
                    problem1.PrintProblem();
                    problem1.SolveProblem();
                    problem1.PrintAnswer();
                    Console.WriteLine("------------------------------\n");
                    break;

                case "2":
                    Console.WriteLine("\n\nCase 2:\n\n");
                    IProblem problem2 = new Problem2();
                    problem2.PrintProblem();
                    problem2.SolveProblem();
                    problem2.PrintAnswer();
                    Console.WriteLine("------------------------------\n");
                    break;

                case "3":
                    Console.WriteLine("\n\nCase 3:\n\n");
                    IProblem problem3 = new Problem3();
                    problem3.PrintProblem();
                    problem3.SolveProblem();
                    problem3.PrintAnswer();
                    Console.WriteLine("------------------------------\n");
                    break;

                case "4":
                    Console.WriteLine("\n\nCase 4:\n\n");
                    IProblem problem4 = new Problem4();
                    problem4.PrintProblem();
                    problem4.SolveProblem();
                    problem4.PrintAnswer();
                    Console.WriteLine("------------------------------\n");
                    break;

                case "5":
                    Console.WriteLine("\n\nCase 5:\n\n");
                    IProblem problem5 = new Problem5();
                    problem5.PrintProblem();
                    problem5.SolveProblem();
                    problem5.PrintAnswer();
                    Console.WriteLine("------------------------------\n");
                    break;

                case "6":
                    Console.WriteLine("\n\nCase 6:\n\n");
                    IProblem problem6 = new Problem6();
                    problem6.PrintProblem();
                    problem6.SolveProblem();
                    problem6.PrintAnswer();
                    Console.WriteLine("------------------------------\n");
                    break;

                case "7":
                    Console.WriteLine("\n\nCase 7:\n\n");
                    IProblem problem7 = new Problem7();
                    problem7.PrintProblem();
                    problem7.SolveProblem();
                    problem7.PrintAnswer();
                    Console.WriteLine("------------------------------\n");
                    break;

                case "8":
                    Console.WriteLine("\n\nCase 8:\n\n");
                    IProblem problem8 = new Problem8();
                    problem8.PrintProblem();
                    problem8.SolveProblem();
                    problem8.PrintAnswer();
                    Console.WriteLine("------------------------------\n");
                    break;

                case "9":
                    Console.WriteLine("\n\nCase 9:\n\n");
                    IProblem problem9 = new Problem9();
                    problem9.PrintProblem();
                    problem9.SolveProblem();
                    problem9.PrintAnswer();
                    Console.WriteLine("------------------------------\n");
                    break;

                case "10":
                    var reader = new PokerHandsReader();
                    reader.PrintLines();
                    break;

                case "n":
                    endApp = true;
                    break;

                default:
                    Console.WriteLine("Not an option.");
                    Console.Write("Press 'n' and Enter to close the app, or press any other key and Enter to continue: ");
                    break;
                }
            }
            return;
        }
示例#26
0
 public void Problem4_ShuldReturn_906609()
 {
     Assert.AreEqual(Problem4.FindLargestPalindrome(3), 906609);
 }
示例#27
0
        static void Main(string[] args)
        {
            var listHelper  = new ListHelper();
            var timeHelper  = new TimeHelper();
            var primeHelper = new PrimeHelper();

            bool exit = false;

            while (!exit)
            {
                Console.Write("Menu: ");
                string input = Console.ReadLine().ToLower();

                DateTime    start        = DateTime.Now;
                List <long> problemsDone = new List <long> ()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                };

                bool isNumeric = int.TryParse(input, out int problemNumber);

                if (isNumeric && problemsDone.Contains(problemNumber))
                {
                    InvokeProblemSolveMethod(problemNumber);
                    timeHelper.TimeToSolve(start);
                }
                else
                {
                    switch (input)
                    {
                    case "pf":
                        primeHelper.WritePrimeFactorisation();
                        break;

                    case "pal":
                        var p4 = new Problem4();
                        Console.Write("Type any number to see if its a palindrom: ");
                        int i = Int32.Parse(Console.ReadLine());
                        Console.WriteLine(p4.NumberIsPalindrom(i));
                        break;

                    case "po":
                        Console.Write("Type any number to see the primes up to this ordinal: ");
                        long j = Int64.Parse(Console.ReadLine());
                        Console.WriteLine(listHelper.ListItems(primeHelper.PrimesUpToOrdinal(j)));
                        break;

                    case "e":
                        exit = true;
                        Console.WriteLine("Exitting");
                        break;

                    case "help":
                        Console.WriteLine("Options: Problem <n> = <n>, Prime Factorisation = pf, Is number palindrom = pal, Exit = e");
                        Console.WriteLine($"Problems Completed: {listHelper.ListItems (problemsDone)}");
                        break;

                    default:
                        Console.WriteLine("Not a valid option, write 'help' to see available options");
                        break;
                    }
                }
                Console.WriteLine("---------------");
            }
        }
示例#28
0
        public void Strategy1Test()
        {
            var sleepLog = Problem4.ReadLogs(TestInput);

            Assert.AreEqual(240, Problem4.Strategy1(sleepLog));
        }
 public void Problem4_ShouldReturn_906609()
 {
     Assert.Equal(Problem4.LargestThreeDigitPalindrome(), 906609);
 }
示例#30
0
        public void Strategy2Test()
        {
            var sleepLog = Problem4.ReadLogs(TestInput);

            Assert.AreEqual(4455, Problem4.Strategy2(sleepLog));
        }