Exemple #1
0
        public static void Run()
        {
            var input      = ConvertInput(File.ReadAllText("Inputs/Day18.txt"));
            var timer      = new MyTimer();
            var expression = new MathRdp();

            Run(ConvertInput("2 * 3 + (4 * 5)"), expression).Should().Be(26);
            Run(ConvertInput("5 + (8 * 3 + 9 + 3 * 4 * 3)"), expression).Should().Be(437);
            Run(ConvertInput("5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))"), expression).Should().Be(12240);
            Run(ConvertInput("((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2"), expression).Should().Be(13632);
            Run(input, expression).Should().Be(464478013511L);

            timer.Lap();
            expression = new MathRdpWithPrecedence();
            Run(ConvertInput("1 + (2 * 3) + (4 * (5 + 6))"), expression).Should().Be(51);
            Run(ConvertInput("2 * 3 + (4 * 5)"), expression).Should().Be(46);
            Run(ConvertInput("5 + (8 * 3 + 9 + 3 * 4 * 3)"), expression).Should().Be(1445);
            Run(ConvertInput("5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))"), expression).Should().Be(669060);
            Run(ConvertInput("((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2"), expression).Should().Be(23340);
            Run(input, expression).Should().Be(85660197232452L);

            timer.Lap();
            timer.Total();
        }
Exemple #2
0
 private static long Run(IEnumerable <List <MathToken> > state, MathRdp expression)
 {
     return(state.Sum(line => expression.Expression(new Queue <MathToken>(line))));
 }