예제 #1
0
        public void Part2()
        {
            InitGrid();
            // start in the middle
            IntCode intCode = new IntCode("Day11", Instructions);
            Robot   robot   = new Robot(intCode, Grid, 1);

            List <Task> tasks = new List <Task>();

            // this block doesn't like to be put in a loop - channel sync crashes
            tasks.Add(Task.Run(() => { intCode.RunIntCode(); }));
            tasks.Add(Task.Run(() => { robot.Run(); }));

            Task.WaitAll(tasks.ToArray());

            for (int y = robot.MaxY; y >= robot.MinY; y--)
            {
                for (int x = robot.MinX; x <= robot.MaxX; x++)
                {
                    Console.Write("{0}", (Grid[x, y] == 1) ? '#' : ' ');
                }
                Console.WriteLine();
            }
            int rslt = robot.ChangeCount;

            Console.WriteLine("Part1 {0}", rslt);
        }
예제 #2
0
        public void Part1()
        {
            InitGrid();
            // start in the middle
            IntCode intCode = new IntCode("Day11", Instructions);
            Robot   robot   = new Robot(intCode, Grid, 0);

            List <Task> tasks = new List <Task>();

            // this block doesn't like to be put in a loop - channel sync crashes
            tasks.Add(Task.Run(() => { intCode.RunIntCode(); }));
            tasks.Add(Task.Run(() => { robot.Run(); }));

            Task.WaitAll(tasks.ToArray());

            int rslt = robot.ChangeCount;

            Console.WriteLine("Part1 {0}", rslt);
        }