コード例 #1
0
        public static int AdventOfCode2019_17_1(List <long> input)
        {
            var intCodeVM = new IntCodeVM(input.ToArray().ToList());
            var output    = intCodeVM.Run(null);
            var x         = 0;
            var y         = 0;

            var grid = new Dictionary <Point, char>();

            for (int i = 0; i < output.Count; i++)
            {
                switch (output[i])
                {
                case 10:
                    x = -1;
                    y++;
                    break;

                default:
                    grid.Add(new Point(x, y), Convert.ToChar(output[i]));
                    break;
                }
                x++;
            }

            for (int _y = 0; _y <= grid.Keys.Max(k => k.Y); _y++)
            {
                for (int _x = 0; _x <= grid.Keys.Max(k => k.X); _x++)
                {
                    Console.Write(grid[new Point(_x, _y)]);
                }
                Console.WriteLine();
            }

            List <Point> intersections = new List <Point>();

            foreach (var point in grid)
            {
                if (point.Value == '#' && IsIntersection(point.Key, grid))
                {
                    intersections.Add(point.Key);
                }
            }
            var total = 0;

            foreach (var point in intersections)
            {
                total += point.X * point.Y;
            }

            return(total);
        }
コード例 #2
0
        public static long AdventOfCode2019_17_2(List <long> input)
        {
            var enabledInput = input.ToArray().ToList();

            enabledInput[0] = 2;

            var inputParameters = new List <long>();

            //Insert MethodChain
            inputParameters.AddRange("A,B,A,B,C,B,C,A,C,C".ToArray().ToList().Select(c => (int)c).Select(i => (long)i).ToList());
            inputParameters.Add(10);

            ////Insert Method A         R12 L10 L10
            inputParameters.AddRange("R,12,L,10,L,10".ToArray().ToList().Select(c => (int)c).Select(i => (long)i).ToList());
            inputParameters.Add(10);

            ////Insert Method B         L6 L12 R12 L4
            inputParameters.AddRange("L,6,L,12,R,12,L,4".ToArray().ToList().Select(c => (int)c).Select(i => (long)i).ToList());
            inputParameters.Add(10);


            //Insert Method C  L12 R12 L6
            inputParameters.AddRange("L,12,R,12,L,6".ToArray().ToList().Select(c => (int)c).Select(i => (long)i).ToList());
            inputParameters.Add(10);

            //Insert continuous video feed
            inputParameters.Add('n');
            inputParameters.Add(10);

            var intCodeVM = new IntCodeVM(enabledInput);

            var output = intCodeVM.Run(inputParameters);

            //Route puzzling
            //R12 L10 L10                   A
            //L6 L12 R12 L4                 B
            //R12 L10 L10                   A
            //L6 L12 R12 L4                 B
            //L12 R12 L6                    C
            //L6 L12 R12 L4                 B
            //L12 R12 L6                    C
            //R12 L10 L10                   A
            //L12 R12 L6                    C
            //L12 R12 L6                    C

            return(output.Last());
        }
コード例 #3
0
ファイル: Day19.cs プロジェクト: KarelLannoy/AdventOfCode2019
        //private static int AdventOfCode2019_19_1_bis(List<long> input)
        //{
        //    Dictionary<Point, long> result = new Dictionary<Point, long>();

        //    for (int y = 0; y < 50; y++)
        //    {
        //        for (int x = 0; x < 50; x++)
        //        {
        //            IntCodeVM computer = new IntCodeVM(input.ToArray().ToList());
        //            var inputParameters = new List<long>() { x, y };
        //            var output = computer.Run(inputParameters);
        //            result.Add(new Point(x, y), output[0]);
        //            Console.Write(output[0]);
        //        }
        //        Console.WriteLine();
        //    }

        //    return result.Count(kvp => kvp.Value == 1);

        //}

        public static int AdventOfCode2019_19_1(List <long> input)
        {
            Dictionary <Point, long> result = new Dictionary <Point, long>();

            result.Add(new Point(0, 0), 1);

            int x       = 0;
            int y       = 3;
            int minX    = 0;
            var xLength = 1;

            while (y < 120)
            {
                bool start = true;
                bool end   = false;
                x = 0;
                var xLengthStart = 0;
                var xLengthEnd   = 0;
                while (x < 120)
                {
                    if (x < minX)
                    {
                        x = minX;
                    }

                    IntCodeVM computer        = new IntCodeVM(input.ToArray().ToList());
                    var       inputParameters = new List <long>()
                    {
                        x, y
                    };
                    var output = computer.Run(inputParameters);
                    if (output[0] == 1)
                    {
                        if (start)
                        {
                            xLengthStart = x;

                            for (int i = 0; i < xLength - 1; i++)
                            {
                                result.Add(new Point(x, y), output[0]);
                                x++;
                            }
                            start = false;
                            end   = true;
                            continue;
                        }
                        else
                        {
                            result.Add(new Point(x, y), output[0]);
                        }
                    }
                    else
                    {
                        if (start)
                        {
                            minX++;
                        }
                        if (end)
                        {
                            xLengthEnd = x;
                            xLength    = xLengthEnd - xLengthStart;
                            break;
                        }
                    }
                    x++;
                }
                y++;
            }

            for (int _y = 0; _y < 50; _y++)
            {
                for (int _x = 0; _x < 50; _x++)
                {
                    if (result.ContainsKey(new Point(_x, _y)))
                    {
                        Console.Write(result[new Point(_x, _y)]);
                    }
                    else
                    {
                        Console.Write("0");
                    }
                }
                Console.WriteLine();
            }

            return(result.Count(kvp => kvp.Value == 1 && kvp.Key.X < 50));
        }
コード例 #4
0
ファイル: Day19.cs プロジェクト: KarelLannoy/AdventOfCode2019
        public static int AdventOfCode2019_19_2(List <long> input)
        {
            Dictionary <Point, long> result = new Dictionary <Point, long>();

            result.Add(new Point(0, 0), 1);

            int x       = 0;
            int y       = 3;
            int minX    = 0;
            var xLength = 1;

            while (y < 2000)
            {
                bool start = true;
                bool end   = false;
                x = 0;
                var xLengthStart = 0;
                var xLengthEnd   = 0;
                while (x < 2000)
                {
                    if (x < minX)
                    {
                        x = minX;
                    }

                    IntCodeVM computer        = new IntCodeVM(input.ToArray().ToList());
                    var       inputParameters = new List <long>()
                    {
                        x, y
                    };
                    var output = computer.Run(inputParameters);
                    if (output[0] == 1)
                    {
                        if (start)
                        {
                            xLengthStart = x;

                            for (int i = 0; i < xLength - 1; i++)
                            {
                                result.Add(new Point(x, y), output[0]);
                                x++;
                            }
                            start = false;
                            end   = true;
                            continue;
                        }
                        else
                        {
                            result.Add(new Point(x, y), output[0]);
                        }
                    }
                    else
                    {
                        if (start)
                        {
                            minX++;
                        }
                        if (end)
                        {
                            xLengthEnd = x;
                            xLength    = xLengthEnd - xLengthStart;
                            break;
                        }
                    }
                    x++;
                }
                y++;
            }

            var lines = result.GroupBy(kvp => kvp.Key.Y).OrderBy(kvp => kvp.Key).ToList();

            for (int i = 0; i < lines.Count(); i++)
            {
                Point beginPoint = new Point(0, 0);
                if (IsThisTheSquareEndLine(lines[i], lines, out beginPoint))
                {
                    return(beginPoint.X * 10000 + beginPoint.Y);
                }
            }

            return(0);
        }