Exemple #1
0
        public static void Run()
        {
            var input  = ConvertInput(File.ReadAllText("Inputs/Day17.txt"), 3);
            var sample = ConvertInput(@".#.
..#
###", 3);

            var timer = new MyTimer();

            Run(sample).Should().Be(112);
            Run(input).Should().Be(319);

            timer.Lap();

            var input2  = ConvertInput(File.ReadAllText("Inputs/Day17.txt"), 4);
            var sample2 = ConvertInput(@".#.
..#
###", 4);

            Run(sample2).Should().Be(848);
            timer.Lap();
            Run(input2).Should().Be(2324);


            timer.Lap();
            timer.Total();
        }
Exemple #2
0
        public static void Run()
        {
            var timer = new MyTimer();

            Part1(Sample).Should().Be(25);
            Part1(Input).Should().Be(1177);

            timer.Lap();

            Part2(Sample).Should().Be(286);
            Part2(Input).Should().Be(46530);

            timer.Lap();
            timer.Total();
        }
Exemple #3
0
        public static void Run()
        {
            var timer = new MyTimer();

            Part1(Sample).Should().Be(165);
            Part1(Input).Should().Be(5902420735773L);

            timer.Lap();

            Part2(Sample2).Should().Be(208);
            Part2(Input).Should().Be(3801988250775L);

            timer.Lap();
            timer.Total();
        }
Exemple #4
0
        public static void Run()
        {
            var input  = ConvertInput(File.ReadAllText("Inputs/Day22Input.txt"));
            var sample = ConvertInput(File.ReadAllText("Inputs/Day22Sample.txt"));
            var timer  = new MyTimer();

            PlayCombat(sample).Should().Be(306);
            PlayCombat(input).Should().Be(34005);

            timer.Lap();

            // Recursive termination check
            PlayRecursiveCombat(ConvertInput(@"Player 1:
43
19

Player 2:
2
29
14"), out var _);

            PlayRecursiveCombat(sample, out _).Should().Be(291);
            PlayRecursiveCombat(input, out _).Should().Be(32731);

            timer.Total();
        }
Exemple #5
0
        public static void Run()
        {
            var input = ConvertInput(File.ReadAllText("Inputs/Day24Input.txt"));

            var sample = ConvertInput(File.ReadAllText("Inputs/Day24Sample.txt"));
            var timer  = new MyTimer();

            Run(sample).Should().Be(10);
            Run(input).Should().Be(386);

            timer.Lap();

            Run2(sample, 100).Should().Be(2208);
            timer.Lap();
            Run2(input, 100).Should().Be(4214);
            timer.Lap();
            timer.Total();
        }
Exemple #6
0
        public static void Run()
        {
            var input  = ConvertInput(File.ReadAllText("Inputs/Day16.txt"));
            var sample = ConvertInput(@"class: 1-3 or 5-7
row: 6-11 or 33-44
seat: 13-40 or 45-50

your ticket:
7,1,14

nearby tickets:
7,3,47
40,4,50
55,2,20
38,6,12");

            var sample2 = ConvertInput(@"class: 0-1 or 4-19
row: 0-5 or 8-19
seat: 0-13 or 16-19

your ticket:
11,12,13

nearby tickets:
3,9,18
15,1,5
5,14,9");

            var timer = new MyTimer();

            Part1(sample).Should().Be(71);
            Part1(input).Should().Be(18142L);

            timer.Lap();

            GetPositions(sample2)
            .Select(it => it.Name)
            .Should()
            .BeEquivalentTo("row", "class", "seat");
            Part2(input).Should().Be(1069784384303);

            timer.Lap();
            timer.Total();
        }
Exemple #7
0
        public static void Run()
        {
            var input = ConvertInput("253149867");

            var sample = ConvertInput("389125467");
            var timer  = new MyTimer();

            Run1(sample.Copy(), 10).Should().Be("92658374");
            Run1(sample.Copy(), 100).Should().Be("67384529");
            Run1(input.Copy(), 100).Should().Be("34952786");

            timer.Lap();
            Run2(sample.Copy().AddRange(Enumerable.Range(10, 1_000_000 - 9)), 10_000_000).Should().Be(149245887792);
            timer.Lap();
            Run2(input.Copy().AddRange(Enumerable.Range(10, 1_000_000 - 9)), 10_000_000).Should().Be(505334281774);
            timer.Lap();


            timer.Total();
        }
Exemple #8
0
        public static void Run()
        {
            var timer = new MyTimer();

            Part1(0, 3, 6).Should().Be(436);
            Part1(1, 3, 2).Should().Be(1);
            Part1(2, 1, 3).Should().Be(10);
            Part1(1, 2, 3).Should().Be(27);
            Part1(2, 3, 1).Should().Be(78);
            Part1(3, 2, 1).Should().Be(438);
            Part1(3, 1, 2).Should().Be(1836);
            Part1(9, 3, 1, 0, 8, 4).Should().Be(371);

            timer.Lap();

            Part2(0, 3, 6).Should().Be(175594);
            timer.Lap();
            Part2(9, 3, 1, 0, 8, 4).Should().Be(352);

            timer.Lap();
            timer.Total();
        }
Exemple #9
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 #10
0
        public static void Run()
        {
            var input  = ConvertInput(File.ReadAllText("Inputs/Day21Input.txt")).ToList();
            var sample = ConvertInput(File.ReadAllText("Inputs/Day21Sample.txt")).ToList();
            var timer  = new MyTimer();

            Run1(sample, out var sampleCanonical).Should().Be(5);
            Run1(input, out var inputCanonical).Should().Be(2412);

            sampleCanonical.Should().Be("mxmxvkd,sqjhc,fvjkl");
            inputCanonical.Should().Be("mfp,mgvfmvp,nhdjth,hcdchl,dvkbjh,dcvrf,bcjz,mhnrqp");

            timer.Lap();


            timer.Total();
        }
Exemple #11
0
        public static void Run()
        {
            var input  = ConvertInput(File.ReadAllText("Inputs/Day20.txt"));
            var sample = ConvertInput(File.ReadAllText("Inputs/Day20Sample.txt"));
            var timer  = new MyTimer();

            var sample2 = new List <Tile>
            {
                new Tile(new[] { 11, 1, 2, 10 }, 100, 0),
                new Tile(new[] { 14, 15, 4, 1 }, 200, 1),
                new Tile(new[] { 2, 3, 13, 12 }, 300, 2),
                new Tile(new[] { 4, 16, 17, 3 }, 400, 3)
            };

            var sample3 = new List <Tile>
            {
                new Tile(new[] { 11, 1, 2, 10 }, 100, 0),
                new Tile(new[] { 14, 15, 4, 1 }, 200, 1),
                new Tile(new[] { 2, 768, 13, 12 }, 300, 2),
                new Tile(new[] { 17, 16, 4, 3 }, 400, 3)
            };

            Run(sample2, 2, out _).Should().Be(100L * 200L * 300L * 400L);
            Run(sample3, 2, out _).Should().Be(100L * 200L * 300L * 400L);

            Run(sample, 3, out var sampleGrid).Should().Be(20899048083289);
            Run(input, 12, out var inputGrid).Should().Be(15670959891893L);

            timer.Lap();

            var seaMonster = new List <string>
            {
                "                  # ",
                "#    ##    ##    ###",
                " #  #  #  #  #  #   "
            };

            Run2(sampleGrid, seaMonster).Should().Be(273);
            Run2(inputGrid, seaMonster).Should().Be(1964);

            timer.Total();
        }
Exemple #12
0
        public static void Run()
        {
            var input = ConvertInput(File.ReadAllText("Inputs/Day19.txt"));
            var timer = new MyTimer();

            var sample1 = ConvertInput(@"0: 1 2
1: ""a""
2: 1 3 | 3 1
3: ""b""

aab
aba");

            var sample2 = ConvertInput(@"0: 4 1 5
1: 2 3 | 3 2
2: 4 4 | 5 5
3: 4 5 | 5 4
4: ""a""
5: ""b""

ababbb
bababa
abbbab
aaabbb
aaaabbb");

            Run(sample1).Should().Be(2);
            Run(sample2).Should().Be(2);
            Run(input).Should().Be(120);

            timer.Lap();

            var sample5 = ConvertInput(@"0: 11 | 8
8: 42 | 42 8
11: 42 31 | 42 11 31
42: ""a""
31: ""b""

ab
aabb
aaabbb
aaaabbbb");

            var sample4 = ConvertInput(@"42: 9 14 | 10 1
9: 14 27 | 1 26
10: 23 14 | 28 1
1: ""a""
11: 42 31
5: 1 14 | 15 1
19: 14 1 | 14 14
12: 24 14 | 19 1
16: 15 1 | 14 14
31: 14 17 | 1 13
6: 14 14 | 1 14
2: 1 24 | 14 4
0: 8 11
13: 14 3 | 1 12
15: 1 | 14
17: 14 2 | 1 7
23: 25 1 | 22 14
28: 16 1
4: 1 1
20: 14 14 | 1 15
3: 5 14 | 16 1
27: 1 6 | 14 18
14: ""b""
21: 14 1 | 1 14
25: 1 1 | 1 14
22: 14 14
8: 42
26: 14 22 | 1 20
18: 15 15
7: 14 5 | 1 21
24: 14 1

abbbbbabbbaaaababbaabbbbabababbbabbbbbbabaaaa
bbabbbbaabaabba
babbbbaabbbbbabbbbbbaabaaabaaa
aaabbbbbbaaaabaababaabababbabaaabbababababaaa
bbbbbbbaaaabbbbaaabbabaaa
bbbababbbbaaaaaaaabbababaaababaabab
ababaaaaaabaaab
ababaaaaabbbaba
baabbaaaabbaaaababbaababb
abbbbabbbbaaaababbbbbbaaaababb
aaaaabbaabaaaaababaa
aaaabbaaaabbaaa
aaaabbaabbaaaaaaabbbabbbaaabbaabaaa
babaaabbbaaabaababbaabababaaab
aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba");

            //Run(sample3).Should().Be(3);
            //Run(sample4).Should().Be(3);
            Run(sample5).Should().Be(4);
            Run2(sample4).Should().Be(12);
            timer.Lap();
            Run2(input).Should().Be(350);

            timer.Lap();
            timer.Total();
        }