Example #1
0
        public void Problem001()
        {
            var problem = new Problem01();

            var answer = problem.Solve();

            Assert.That (answer, Is.EqualTo(233168));
        }
   public static void Main() 
   {
        var problem01 = new Problem01();
        System.Console.WriteLine("Answer 01: " + problem01.Solve());

        var problem02 = new Problem02();
        System.Console.WriteLine("Answer 02: " + problem02.GetAnswer());
        
        var problem03 = new Problem03();
        System.Console.WriteLine("Answer 03: " + problem03.AnswerNumber);
        
        var problem04 = new Problem04();
        System.Console.WriteLine("Answer 04: " + problem04.getAnswer());
        
        var problem05 = new Problem05();
        System.Console.WriteLine("Answer 05: " + problem05.getAnswer());
    }
Example #3
0
    static void Main(string[] args)
    {
        var      stopWatch = new System.Diagnostics.Stopwatch();
        IProblem problem;

        stopWatch.Start();

        //var problem = new FizzBuzz();
        problem = new Day01();

        #region Euler

        problem = new Problem01();
        //problem = new Problem02();
        //problem = new Problem03();
        //problem = new Problem04();
        //problem = new Problem05();
        //problem = new Problem06();
        //problem = new Problem07();
        //problem = new Problem08();
        //problem = new Problem09();
        //problem = new Problem10();
        //problem = new Problem11();
        //problem = new Problem12();
        //problem = new Problem13();
        //problem = new Problem14();
        //problem = new Problem15();
        //problem = new Problem16();
        //problem = new Problem17();
        //            problem = new Problem18();

        #endregion

        var answer = problem.Solution();
        stopWatch.Stop();

        Console.WriteLine(problem.GetType().Name + @" = " + answer.Description);

        Console.WriteLine(stopWatch.Elapsed + @" Elapsed");
        Console.WriteLine(stopWatch.ElapsedMilliseconds + @" Elapsed milliSeconds");
        Console.WriteLine(stopWatch.ElapsedTicks + @" ticks");
        Console.ReadLine();
    }
Example #4
0
        public void Problem01Should()
        {
            int startingFrequency = 0;

            string[] frequencyChanges = new string[] { "0", "+1", "-2", "+3", "+1" };

            int part3ShouldBe = 3;

            int part1Result = Problem01.CalculateResultingFrequency(startingFrequency, frequencyChanges);

            Assert.Equal(part3ShouldBe, part1Result);

            string[] frequencyChanges2 = new string[] { "+3", "+3", "+4", "-2", "-4" };

            int part2ShouldBe = 10;

            int part2Result = Problem01.GetFirstRepeatingFrequency(startingFrequency, frequencyChanges2);

            Assert.Equal(part2ShouldBe, part2Result);
        }
Example #5
0
        static void Main(string[] args)
        {
            // Problem01

            // get input from file
            string[] problem01Input = GetStringArrayFromInputFile("Problem01");

            int resultProblem1Part1 = Problem01.CalculateResultingFrequency(0, problem01Input);

            Console.WriteLine("Problem 01 Part 01 result is: {0}", resultProblem1Part1);

            int resultProblem1Part2 = Problem01.GetFirstRepeatingFrequency(0, problem01Input);

            Console.WriteLine("Problem 01 Part 02 result is: {0}", resultProblem1Part2);

            // Problem02

            // get input from file
            string[] problem02Input = GetStringArrayFromInputFile("Problem02");

            int resultProblem2Part1 = Problem02.ComputeChecksum(problem02Input);

            Console.WriteLine("Problem 02 Part 01 result is: {0}", resultProblem2Part1);

            string resultProblem2Part2 = Problem02.GetOffByOneStringPair(problem02Input, true);

            Console.WriteLine("Problem 02 Part 02 result is: {0}", resultProblem2Part2);

            // Problem05

            // get input from file
            string problem05Input = GetStringFromInputFile("Problem05");

            int resultProblem5Part1 = Problem05.RemoveAdjacentLetters(problem05Input);

            Console.WriteLine("Problem 05 Part 01 result is: {0}", resultProblem5Part1);

            int resultProblem5Part2 = Problem05.GetSmallestSubstringLength(problem05Input);

            Console.WriteLine("Problem 05 Part 02 result is: {0}", resultProblem5Part2);
        }
    public static void Main()
    {
        var problem01 = new Problem01();

        System.Console.WriteLine("Answer 01: " + problem01.Solve());

        var problem02 = new Problem02();

        System.Console.WriteLine("Answer 02: " + problem02.GetAnswer());

        var problem03 = new Problem03();

        System.Console.WriteLine("Answer 03: " + problem03.AnswerNumber);

        var problem04 = new Problem04();

        System.Console.WriteLine("Answer 04: " + problem04.getAnswer());

        var problem05 = new Problem05();

        System.Console.WriteLine("Answer 05: " + problem05.getAnswer());
    }
        public void Problem01_Return_Result_233168()
        {
            int act = Problem01.MultiplesOf3And5();

            Assert.True(act.Equals(233168));
        }
Example #8
0
    public static void p00_fun(ref p00Data data, int problem, int option, int n, double[] x, ref double[] f)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    P00_FUN evaluates the integrand for any problem.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    31 July 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int PROBLEM, the index of the problem.
    //
    //    Input, int OPTION:
    //    0, integrand is f(x).
    //    1, integrand is exp(-x*x) * f(x);
    //    2, integrand is exp(-x*x/2) * f(x);
    //
    //    Input, int N, the number of points.
    //
    //    Input, double X[N], the evaluation points.
    //
    //    Output, double F[N], the function values.
    //
    {
        switch (problem)
        {
        case 1:
            Problem01.p01_fun(option, n, x, ref f);
            break;

        case 2:
            Problem02.p02_fun(option, n, x, ref f);
            break;

        case 3:
            Problem03.p03_fun(option, n, x, ref f);
            break;

        case 4:
            Problem04.p04_fun(option, n, x, ref f);
            break;

        case 5:
            Problem05.p05_fun(option, n, x, ref f);
            break;

        case 6:
            Problem06.p06_fun(ref data.p6data, option, n, x, ref f);
            break;

        case 7:
            Problem07.p07_fun(option, n, x, ref f);
            break;

        case 8:
            Problem08.p08_fun(option, n, x, ref f);
            break;

        default:
            Console.WriteLine("");
            Console.WriteLine("P00_FUN - Fatal error!");
            Console.WriteLine("  Illegal problem number = " + problem + "");
            break;
        }
    }
Example #9
0
    public static string p00_title(int problem)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    P00_TITLE returns the title for any problem.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 February 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int PROBLEM, the index of the problem.
    //
    //    Output, string P00_TITLE, the title of the problem.
    //
    {
        string title;

        switch (problem)
        {
        case 1:
            title = Problem01.p01_title();
            break;

        case 2:
            title = Problem02.p02_title();
            break;

        case 3:
            title = Problem03.p03_title();
            break;

        case 4:
            title = Problem04.p04_title();
            break;

        case 5:
            title = Problem05.p05_title();
            break;

        case 6:
            title = Problem06.p06_title();
            break;

        case 7:
            title = Problem07.p07_title();
            break;

        case 8:
            title = Problem08.p08_title();
            break;

        default:
            Console.WriteLine("");
            Console.WriteLine("P00_TITLE - Fatal error!");
            Console.WriteLine("  Illegal problem number = " + problem + "");
            return("");
        }

        return(title);
    }
Example #10
0
    public static double p00_exact(ref p00Data data, int problem)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    P00_EXACT returns the exact integral for any problem.
    //
    //  Discussion:
    //
    //    This routine provides a "generic" interface to the exact integral
    //    routines for the various problems, and allows a problem to be called
    //    by index (PROBLEM) rather than by name.
    //
    //    In most cases, the "exact" value of the integral is not given;
    //    instead a "respectable" approximation is available.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    31 Julyl 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int PROBLEM, the index of the problem.
    //
    //    Output, double P00_EXACT, the exact value of the integral.
    //
    {
        double exact;

        switch (problem)
        {
        case 1:
            exact = Problem01.p01_exact();
            break;

        case 2:
            exact = Problem02.p02_exact();
            break;

        case 3:
            exact = Problem03.p03_exact();
            break;

        case 4:
            exact = Problem04.p04_exact();
            break;

        case 5:
            exact = Problem05.p05_exact();
            break;

        case 6:
            exact = Problem06.p06_exact(ref data.p6data);
            break;

        case 7:
            exact = Problem07.p07_exact();
            break;

        case 8:
            exact = Problem08.p08_exact();
            break;

        default:
            Console.WriteLine("");
            Console.WriteLine("P00_EXACT - Fatal error!");
            Console.WriteLine("  Illegal problem number = " + problem + "");
            return(1);
        }

        return(exact);
    }