示例#1
0
        public static async Task Run()
        {
            var input = (await File.ReadAllTextAsync("inputs\\21.txt"));

            var myIntMachine = new SynchronousIntMachine(input);

            myIntMachine.addASCIILine("OR A J\n");
            myIntMachine.addASCIILine("AND B J\n");
            myIntMachine.addASCIILine("AND C J\n");
            myIntMachine.addASCIILine("NOT J J\n");
            myIntMachine.addASCIILine("AND D J\n");
            myIntMachine.addASCIILine("WALK\n");

            var c = 0;

            while (myIntMachine.RunUntilBlockOrComplete() != SynchronousIntMachine.ReturnCode.Completed)
            {
                c++;
            }

            Console.WriteLine("Part 1: " + myIntMachine.OutputQueue.Last());

            myIntMachine = new SynchronousIntMachine(input);

            myIntMachine.addASCIILine("OR A J\n");
            myIntMachine.addASCIILine("AND B J\n");
            myIntMachine.addASCIILine("AND C J\n");
            myIntMachine.addASCIILine("NOT J J\n");
            myIntMachine.addASCIILine("AND D J\n");
            myIntMachine.addASCIILine("OR I T\n");
            myIntMachine.addASCIILine("OR F T\n");
            myIntMachine.addASCIILine("AND E T\n");
            myIntMachine.addASCIILine("OR H T\n");
            myIntMachine.addASCIILine("AND T J\n");
            myIntMachine.addASCIILine("RUN\n");

            c = 0;

            while (myIntMachine.RunUntilBlockOrComplete() != SynchronousIntMachine.ReturnCode.Completed)
            {
                c++;
            }

            Console.WriteLine("Part 2: " + myIntMachine.OutputQueue.Last());
        }
示例#2
0
        public static async Task Run()
        {
            var input = (await File.ReadAllTextAsync("inputs\\17.txt"));

            var myIntMachine = new SynchronousIntMachine(input);

            List <char> lines = new List <char> ();

            if (!File.Exists("outputs\\17.txt"))
            {
                while (myIntMachine.RunUntilBlockOrComplete() != SynchronousIntMachine.ReturnCode.Completed)
                {
                    var o = myIntMachine.OutputQueue.Dequeue();

                    lines.Add((char)o);
                }

                var sb = new StringBuilder();

                lines.ForEach(e => sb.Append(e));

                if (!Directory.Exists("outputs"))
                {
                    Directory.CreateDirectory("outputs");
                }

                await File.WriteAllTextAsync("outputs\\17.txt", sb.ToString(), Encoding.ASCII);
            }

            var scaffold = (await File.ReadAllLinesAsync("outputs\\17.txt", Encoding.ASCII)).Where(e => e != "").ToArray();

            var aparm = 0;

            for (int y = 0; y < scaffold.Length; y++)
            {
                for (int x = 0; x < scaffold [y].Length; x++)
                {
                    aparm += GetIntersect(x, y, scaffold);
                }
            }

            Console.WriteLine("Part 1: " + aparm.ToString());

            myIntMachine = new SynchronousIntMachine(input);

            myIntMachine.SetMemoryRegister(0, 2);

            var A = "L,12,L,8,R,10,R,10\n";
            var B = "L,6,L,4,L,12\n";
            var C = "R,10,L,8,L,4,R,10\n";

            var seq = "A,B,A,B,C,B,A,C,B,C\n";

            //use these to debug your input lengths
            //if you are stuck, try outputting the outputqueue after the vm is done running as ascii text
            // var la = A.ToCharArray ().Length;
            // var lb = B.ToCharArray ().Length;
            // var lc = C.ToCharArray ().Length;
            // var ls = seq.ToCharArray ().Length;

            myIntMachine.addASCIILine(seq);
            myIntMachine.addASCIILine(A);
            myIntMachine.addASCIILine(B);
            myIntMachine.addASCIILine(C);
            myIntMachine.addASCIILine("n\n");

            var c = 0;

            while (myIntMachine.RunUntilBlockOrComplete() != SynchronousIntMachine.ReturnCode.Completed)
            {
                c++;
            }

            var part2 = myIntMachine.OutputQueue.Last();

            Console.WriteLine("Part 2: " + part2.ToString());
        }