예제 #1
0
파일: Day19_5.cs 프로젝트: Delthii/AoC2019
        public override string PartB()
        {
            var input = Lines.First().Split(',').Select(long.Parse).ToArray();
            var inp   = new List <long> {
                5
            };
            var outp = new List <long>();
            var c    = new SeqCompiler(inp, outp, input);

            c.Run();
            return(outp[outp.Count - 1] + "");
        }
예제 #2
0
파일: Day19_9.cs 프로젝트: Delthii/AoC2019
        public override string PartB()
        {
            var program = Lines.First().Split(',').Select(long.Parse).ToArray();
            var inpA    = new List <long> {
                2
            };
            var outA = new List <long>();
            var c    = new SeqCompiler(inpA, outA, program);

            c.Run();

            return(outA[0] + "");
        }
예제 #3
0
        public string Core(IEnumerable <long[]> phases)
        {
            var program = Lines.First().Split(',').Select(long.Parse).ToArray();
            var outputs = new List <long>();

            foreach (var phase in phases)
            {
                var inpA = new List <long> {
                    phase[0], 0
                };
                var inpB = new List <long> {
                    phase[1]
                };
                var inpC = new List <long> {
                    phase[2]
                };
                var inpD = new List <long> {
                    phase[3]
                };
                var inpE = new List <long> {
                    phase[4]
                };
                var ca = new SeqCompiler(inpA, inpB, program.ToArray());
                var cb = new SeqCompiler(inpB, inpC, program.ToArray());
                var cc = new SeqCompiler(inpC, inpD, program.ToArray());
                var cd = new SeqCompiler(inpD, inpE, program.ToArray());
                var ce = new SeqCompiler(inpE, inpA, program.ToArray());
                do
                {
                    while (ca.Step() == State.Running)
                    {
                    }
                    while (cb.Step() == State.Running)
                    {
                    }
                    while (cc.Step() == State.Running)
                    {
                    }
                    while (cd.Step() == State.Running)
                    {
                    }
                    while (ce.Step() == State.Running)
                    {
                    }
                } while (!ce.Done());
                outputs.Add(ce.LastOut);
            }

            return(outputs.Max() + "");
        }
예제 #4
0
파일: Day19_11.cs 프로젝트: Delthii/AoC2019
        public override string PartA()
        {
            var program   = Lines.First().Split(',').Select(long.Parse).ToArray();
            var input     = new List <long>();
            var output    = new List <long>();
            var c         = new SeqCompiler(input, output, program);
            var points    = new Dictionary <Point, long>();
            var position  = new Point(0, 0);
            var direction = Direction.Up;

            points[position] = 1;
            while (c.GetState() != State.Done)
            {
                var color = GetColorAtPosition(points, position);
                input.Add(color);
                Run(c);
                var newColor = output.First();
                output.RemoveAt(0);
                var dir = output.First();
                output.RemoveAt(0);
                points[position] = newColor;

                if (dir == 1)
                {
                    TurnRight(ref direction);
                }
                else
                {
                    TurnLeft(ref direction);
                }

                switch (direction)
                {
                case Direction.Down:
                    position.y++;
                    break;

                case Direction.Up:
                    position.y--;
                    break;

                case Direction.Left:
                    position.x--;
                    break;

                case Direction.Right:
                    position.x++;
                    break;
                }
            }

            for (int i = points.Keys.Select(p => p.y).Min(); i <= points.Keys.Select(p => p.y).Max(); i++)
            {
                for (int j = points.Keys.Select(p => p.x).Min(); j <= points.Keys.Select(p => p.x).Max(); j++)
                {
                    if (points.ContainsKey(new Point(j, i)))
                    {
                        Console.Write(points[new Point(j, i)] == 1L ? '|' : ' ');
                    }
                    else
                    {
                        Console.Write(' ');
                    }
                }
                Console.WriteLine();
            }


            return("");
        }
예제 #5
0
파일: Day19_11.cs 프로젝트: Delthii/AoC2019
 private void Run(SeqCompiler c)
 {
     while (c.Step() == State.Running)
     {
     }
 }