コード例 #1
0
        public void ToASCIITest()
        {
            int _actual = ASCIIHelper.ToASCII('.');

            Assert.AreEqual(46, _actual);
            byte[] _actualArray = ASCIIHelper.ToASCII("Hello");
            CollectionAssert.AreEqual(new byte[5] {
                72, 101, 108, 108, 111
            }, _actualArray);
        }
コード例 #2
0
        /// <inheritdoc />
        public string Part2()
        {
            IntCodeVM2 vm = new IntCodeVM2(program);

            // show prompt
            vm.ExecuteProgram();
            DrawASCIIOutput(vm.GetOutputs());
            vm.ClearOutput();

            // input program
            //
            //  @
            // ##ABCDEFGHI###
            //
            // if D is ground and any of A,B,C aren't then jump (p1)
            // invert T (now equal to C)
            // if ((I OR F) AND E) OR H are ground, then jump
            ASCIIHelper helper = new ASCIIHelper();

            helper.AddLine("NOT A T");
            helper.AddLine("NOT B J");
            helper.AddLine("OR T J");
            helper.AddLine("NOT C T");
            helper.AddLine("OR T J");
            helper.AddLine("AND D J");

            helper.AddLine("AND T T");

            helper.AddLine("OR I T");
            helper.AddLine("OR F T");
            helper.AddLine("AND E T");
            helper.AddLine("OR H T");
            helper.AddLine("AND T J");

            helper.AddLine("RUN");

            vm.AddInput(helper.Convert());

            // output what it showed
            vm.ResumeProgram();

            if (vm.GetLastOutput() > 255)
            {
                Console.WriteLine($"\nhull damage taken: {vm.GetLastOutput()}");
            }
            else
            {
                DrawASCIIOutput(vm.GetOutputs());
            }

            return("");
        }
コード例 #3
0
        public BigInteger Walk()
        {
            var output = brain.Run("WALK");
            int takeN  = output.Count;

            if (output.Last() > 255)
            {
                takeN--;
            }
            if (outputToConsole)
            {
                Console.Write(ASCIIHelper.ASCIIToString(output.Take(takeN)));
            }
            return(output.Last());
        }
コード例 #4
0
        public static string GetRandomString(int length)
        {
            List <string> list = new List <string>();

            for (var i = 0; i < length; i++)
            {
                int[] array = new int[3];
                array[0] = random.Next(1, 10);
                array[1] = random.Next(65, 91);
                array[2] = random.Next(97, 123);
                int num = array[random.Next(0, 3)];
                list.Add(ASCIIHelper.GetASCIIChar(num));
            }

            return(string.Join("", list));
        }
コード例 #5
0
        /// <inheritdoc />
        public string Part1()
        {
            IntCodeVM2 vm = new IntCodeVM2(program);

            // show prompt
            vm.ExecuteProgram();
            DrawASCIIOutput(vm.GetOutputs());
            vm.ClearOutput();

            // input program
            //J = (NOT A OR NOT B OR NOT C) AND D
            //
            //  @
            // ##ABCD###
            //
            // if D is ground and any of A,B,C aren't then jump
            ASCIIHelper helper = new ASCIIHelper();

            helper.AddLine("NOT A T");
            helper.AddLine("NOT B J");
            helper.AddLine("OR T J");
            helper.AddLine("NOT C T");
            helper.AddLine("OR T J");
            helper.AddLine("AND D J");

            helper.AddLine("WALK");

            vm.AddInput(helper.Convert());

            // output what it showed
            vm.ResumeProgram();

            if (vm.GetLastOutput() > 255)
            {
                Console.WriteLine($"\nhull damage taken: {vm.GetLastOutput()}");
            }
            else
            {
                DrawASCIIOutput(vm.GetOutputs());
            }

            return("");
        }
コード例 #6
0
        public void ParseASCIITest()
        {
            char _actual = ASCIIHelper.ParseASCII(46);

            Assert.AreEqual('.', _actual);
        }
コード例 #7
0
ファイル: Day25.cs プロジェクト: w200338/Advent-of-Code-2019
        /// <inheritdoc />
        public string Part1()
        {
            // set to true to play the text adventure
            bool userPlay = false;


            IntCodeVM2 vm = new IntCodeVM2(program);

            vm.ExecuteProgram();

            if (userPlay)
            {
                while (true)
                {
                    // output
                    foreach (long l in vm.GetOutputs())
                    {
                        if (l < 255)
                        {
                            Console.Write((char)l);
                        }
                        else
                        {
                            Console.Write(l);
                        }
                    }

                    vm.ClearOutput();

                    // input
                    string inputLine = Console.ReadLine();

                    ASCIIHelper helper = new ASCIIHelper();
                    helper.AddLine(inputLine);

                    vm.AddInput(helper.Convert());
                    vm.ResumeProgram();
                }
            }
            else
            {
                // list of inputs to get to the end
                List <string> inputs = new List <string>()
                {
                    "south",
                    "take food ration",
                    "west",
                    "north",
                    "north",
                    "east",
                    "take astrolabe",
                    "west",
                    "south",
                    "south",
                    "east",
                    "north",
                    "east",
                    "south",
                    "take weather machine",
                    "west",
                    "take ornament",
                    "east",
                    "north",
                    "east",
                    "east",
                    "east",
                    "south"
                };

                ASCIIHelper helper = new ASCIIHelper();
                foreach (string input in inputs)
                {
                    helper.AddLine(input);
                }

                vm.AddInput(helper.Convert());
                vm.ResumeProgram();

                List <long> output = vm.GetOutputs();
                output.RemoveAt(output.Count - 1);          // remove last \n
                int lastLineStart = output.LastIndexOf(10); // get last sentence

                // convert characters to a string
                StringBuilder lastLine = new StringBuilder();
                for (int i = lastLineStart + 1; i < output.Count; i++)
                {
                    if (output[i] < 255)
                    {
                        lastLine.Append((char)output[i]);
                    }
                    else
                    {
                        lastLine.Append(output[i]);
                    }
                }

                // get the number from the last line
                return(Regex.Match(lastLine.ToString(), @"\d+").Value);
            }

            return($"");
        }
コード例 #8
0
 public string RunString(string input)
 {
     return(ASCIIHelper.ASCIIToString(Run(input)));
 }
コード例 #9
0
 public string RunString()
 {
     return(ASCIIHelper.ASCIIToString(Run()));
 }
コード例 #10
0
 public List <BigInteger> Run(string input, bool newLineAtEnd = true)
 {
     return(Run(ASCIIHelper.StringToASCIIBI(input, newLineAtEnd)));
 }