Ejemplo n.º 1
0
        public void Part1_Answer()
        {
            var day19 = new Day19();

            var(_, actual) = day19.Walk(PUZZLE_INPUT);
            Assert.Equal("YOHREPXWN", actual);
        }
Ejemplo n.º 2
0
        public void Part2_Answer()
        {
            var day19 = new Day19();

            var(steps, _) = day19.Walk(PUZZLE_INPUT);
            Assert.Equal(16734, steps);
        }
Ejemplo n.º 3
0
        private void Run()
        {
            var size     = 100;
            var input    = File.ReadAllText(@"C:\Users\Bakke\source\repos\AdventOfCode2019\AdventOfCode2019\Data\Day19.txt").Split(",").Select(int.Parse).ToArray();
            var analyser = new Day19.BeamAnalyzer(input);

            bool IsAffected(int r, int c)
            {
                var isAffected = analyser.IsAffected(r, c);

                // draw a pixel for each call
                if (!closed)
                {
                    BeginInvoke((MethodInvoker) delegate { UpdateImage(c, r, isAffected ? Color.Green : Color.Red); });
                }
                return(isAffected);
            }

            var(col, row) = Day19.FindBoxStart(size, IsAffected);

            // draw a box around the result to verify
            for (int c1 = col - 5; c1 < col + 5 + size; c1++)
            {
                for (int r2 = row - 5; r2 < row + 5 + size; r2++)
                {
                    IsAffected(c1, r2);
                }
            }

            if (!closed)
            {
                BeginInvoke((MethodInvoker) delegate { DrawBox(col, row, size); });
            }
        }
Ejemplo n.º 4
0
        public void Part2Test2( )
        {
            day19 = new Day19("day19test2");
            var actual = day19.SolvePart2( );

            Assert.AreEqual(12.ToString( ), actual);
        }
Ejemplo n.º 5
0
        public void Day19()
        {
            var day = new Day19();

            Assert.AreEqual(131, day.LocalPointCount());
            Assert.AreEqual(15231022, day.FindFirstSquare(100));
        }
Ejemplo n.º 6
0
            public static void Day21_1_2(IReadOnlyList <string> input)
            {
                var registers    = new int[REGISTERS];
                var ipRegister   = Day19.GetIpRegister(input);
                var instructions = Day19.GetInstructions(input);
                var operators    = Day19.GetOperators();

                var set         = new HashSet <int>();
                int lastNewSeen = 0;

                while (registers[ipRegister] < instructions.Length)
                {
                    var instruction = instructions[registers[ipRegister]];
                    registers = operators[instruction[0]](registers, instruction);

                    if (registers[ipRegister] == 28 &&
                        !set.Contains(registers[3]))
                    {
                        lastNewSeen = registers[3];
                        if (!set.Any())
                        {
                            Console.WriteLine($"Part 1: {lastNewSeen}");
                        }
                        set.Add(lastNewSeen);
                    }
                    else if (registers[ipRegister] == 28)
                    {
                        Console.WriteLine($"Part 2: {lastNewSeen}");
                        break;
                    }

                    registers[ipRegister]++;
                }
            }
Ejemplo n.º 7
0
        public void PartATests(string input, int expectedOutput)
        {
            var day    = new Day19();
            var result = day.SolveA(input);

            Assert.AreEqual(expectedOutput, result);
        }
Ejemplo n.º 8
0
    public void Y2020_Day19_GetMatchCount_Returns_Correct_Value_Part_2(bool applyFix, int expected)
    {
        // Arrange
        string[] input = new[]
        {
            "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",
            string.Empty,
            "abbbbbabbbaaaababbaabbbbabababbbabbbbbbabaaaa",
            "bbabbbbaabaabba",
            "babbbbaabbbbbabbbbbbaabaaabaaa",
            "aaabbbbbbaaaabaababaabababbabaaabbababababaaa",
            "bbbbbbbaaaabbbbaaabbabaaa",
            "bbbababbbbaaaaaaaabbababaaababaabab",
            "ababaaaaaabaaab",
            "ababaaaaabbbaba",
            "baabbaaaabbaaaababbaababb",
            "abbbbabbbbaaaababbbbbbaaaababb",
            "aaaaabbaabaaaaababaa",
            "aaaabbaaaabbaaa",
            "aaaabbaabbaaaaaaabbbabbbaaabbaabaaa",
            "babaaabbbaaabaababbaabababaaab",
            "aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba",
        };

        // Act
        int actual = Day19.GetMatchCount(input, applyFix);

        // Assert
        actual.ShouldBe(expected);
    }
Ejemplo n.º 9
0
    public void Y2020_Day19_GetMatchCount_Returns_Correct_Value_Part_1()
    {
        // Arrange
        string[] input = new[]
        {
            "0: 4 1 5",
            "1: 2 3 | 3 2",
            "2: 4 4 | 5 5",
            "3: 4 5 | 5 4",
            "4: \"a\"",
            "5: \"b\"",
            string.Empty,
            "ababbb",
            "bababa",
            "abbbab",
            "aaabbb",
            "aaaabbb",
        };

        // Act
        int actual = Day19.GetMatchCount(input, applyFix: false);

        // Assert
        actual.ShouldBe(2);
    }
Ejemplo n.º 10
0
        public void Day19()
        {
            var day = new Day19();

            Assert.Equal("XYFDJNRCQA", day.FirstPart());
            Assert.Equal("17450", day.SecondPart());
        }
Ejemplo n.º 11
0
        public void Part1RealPuzzle()
        {
            var input  = GetPuzzleInput();
            var result = Day19.SolvePart1(input);

            Assert.Equal("EPYDUXANIT", result);
        }
Ejemplo n.º 12
0
        public void Part1SamplePuzzle()
        {
            var input  = GetSampleInput();
            var result = Day19.SolvePart1(input);

            Assert.Equal("ABCDEF", result);
        }
Ejemplo n.º 13
0
        //[Fact]
        public void LoopTest()
        {
            var day = new Day19(Inputs.Day19)
            {
                Registers = { [0] = 1 }
            };

            Render(day.Registers);

            for (int i = 0; i < 900000; i++)
            {
                var ended = day.StepProgram();
                if (ended)
                {
                    break;
                }
            }

            for (int i = 0; i < 500000; i++)
            {
                var ended = day.StepProgram();
                Render(day.Registers);
                if (ended)
                {
                    break;
                }
            }

            Assert.True(true);
        }
Ejemplo n.º 14
0
        public void TestPart1()
        {
            int   part1Solution = 279;
            Day19 day           = new Day19();

            day.ExecutePart1().Should().Be(part1Solution);
        }
Ejemplo n.º 15
0
        public void GetDay19Part2AnswerTest()
        {
            int expected = 10180726;
            int actual   = Day19.GetDay19Part2Answer();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 16
0
        public void TestPart2()
        {
            Day19 day           = new Day19();
            int   part2Solution = 384;

            day.ExecutePart2().Should().Be(part2Solution);
        }
Ejemplo n.º 17
0
        public void Part2RealPuzzle()
        {
            var input  = GetPuzzleInput();
            var result = Day19.SolvePart2(input);

            Assert.Equal(17544, result);
        }
Ejemplo n.º 18
0
        public void Test2()
        {
            var result   = Day19.Solve(Input.Trim().Split("\r\n").ToArray(), null, 2);
            var expected = new[] { 1, 5, 6, 0, 0, 0 };

            Assert.Equal(expected, result.state);
        }
Ejemplo n.º 19
0
        public void TestPart2Sample2()
        {
            var input = @"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".Split('\n');

            var parsed = Day19.ParseInput(input);

            parsed.lines.Select(l => l.Replace("\r", "")).Count(line => Day19.CheckRule(parsed.rules, line)).Should().Be(3);

            parsed.rules[8]  = new MonsterRule(8, new[] { 42 }, new[] { 42, 8 });
            parsed.rules[11] = new MonsterRule(11, new[] { 42, 31 }, new[] { 42, 11, 31 });

            parsed.lines.Select(l => l.Replace("\r", "")).Count(line => Day19.CheckRule(parsed.rules, line)).Should().Be(12);
        }
Ejemplo n.º 20
0
        public void CheckCorrectMessages()
        {
            var day19 = new Day19("\\AOCTests\\Day19Tests\\Day19TestInput.txt");

            var answer = day19.CheckMatchingMessages(0);

            Assert.AreEqual(2, answer);
        }
Ejemplo n.º 21
0
        public void CanRunSample()
        {
            var day = new Day19(_testInput);

            day.RunProgram();

            Assert.Equal(6, day.Registers[0]);
        }
Ejemplo n.º 22
0
        //[Fact]
        public void Solve2_a()
        {
            var input  = File.ReadAllLines("C:\\Code\\aoc2018\\aoc2018\\Data\\input19.txt");
            var result = Day19.Solve(input, new[] { 1, 0, 0, 0, 0, 0 }, printFrom: 10000, printTo: "2a");

            _output.WriteLine(string.Join(", ", result.state));
            _output.WriteLine(result.state[0].ToString());
        }
Ejemplo n.º 23
0
        public void Solve()
        {
            var input  = File.ReadAllLines("C:\\Code\\aoc2018\\aoc2018\\Data\\input19.txt");
            var result = Day19.Solve(input);

            _output.WriteLine(result.state[0].ToString());
            _output.WriteLine(result.iterations.ToString());
        }
Ejemplo n.º 24
0
        public void Solve()
        {
            var input  = DataHelper.Get(19);
            var solver = new Day19();
            var result = solver.Solve(input, overrideRules: false);

            Output.WriteLine(result.ToString());
        }
Ejemplo n.º 25
0
        public void CanParse()
        {
            var day = new Day19(_testInput);

            Assert.Equal(0, day.InstructionPointer.IpRegisterIndex);
            Assert.Equal(7, day.Program.Count);
            Assert.IsType <Day16.SetI>(day.Program[1].OpCode);
        }
Ejemplo n.º 26
0
 public void Pattern()
 {
     for (int i = 1; i < 101; i++)
     {
         _day19 = new Day19();
         Console.WriteLine(_day19.Simulate(i));
     }
 }
Ejemplo n.º 27
0
        public void Q1()
        {
            var day = new Day19(Inputs.Day19);

            day.RunProgram();

            Assert.Equal(1568, day.Registers[0]);
        }
Ejemplo n.º 28
0
        public void CheckCorrectMessagesWithLoop()
        {
            var day19 = new Day19("\\AOCTests\\Day19Tests\\Day19TestInputPart2.txt");

            var answer = day19.CheckMatchingMessagesFromTheMessage();

            Assert.AreEqual(12, answer);
        }
Ejemplo n.º 29
0
    public static void Y2016_Day19_FindElfThatGetsAllPresents_Returns_Correct_Solution(int count, int version, int expected)
    {
        // Act
        int actual = Day19.FindElfThatGetsAllPresents(count, version);

        // Assert
        actual.ShouldBe(expected);
    }
Ejemplo n.º 30
0
        public void conforms(string s, bool expected)
        {
            var d = new Day19();

            d.GetInput();
            d.ParseInput(d.Input);
            d.Conforms(s).Should().Be(expected);
        }