コード例 #1
0
ファイル: Day9.cs プロジェクト: JoshOlds/AdventOfCode2016
        public void Execute()
        {
            Console.WriteLine("Advent of Code 2016 - Day 9");

            string[] inputArr = null;
            try //Try to read the text file
            {
                inputArr = System.IO.File.ReadAllLines(@"./data/Day9.txt");
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            string[] outputArr = new string[inputArr.Length];
            for (int i = 0; i < inputArr.Length; i++)
            {
                string output = Decompressor_Day9.Decompress(InputManipulator.RemoveAllWhiteSpace(inputArr[i]));
                outputArr[i] = output;
            }

            int count = 0;

            foreach (string s in outputArr)
            {
                count += s.Length;
            }

            Console.WriteLine("Length of Decompressed message: " + count);
        }
コード例 #2
0
ファイル: Day6.cs プロジェクト: JoshOlds/AdventOfCode2016
        public void Execute()
        {
            Console.WriteLine("Advent of Code 2016 - Day 6");
            string[] inputArr = null;
            try //Try to read the text file
            {
                inputArr = System.IO.File.ReadAllLines(@"./data/Day6.txt");
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
            inputArr = InputManipulator.RowsToColumns(inputArr);

            Console.WriteLine("The decoded message is: " + stringBuilder(inputArr));
            Console.WriteLine("The modified decoded message is: " + modifiedStringBuilder(inputArr));
        }
コード例 #3
0
ファイル: Day7.cs プロジェクト: JoshOlds/AdventOfCode2016
        public void Execute()
        {
            Console.WriteLine("Advent of Code 2016 - Day 7");
            string[] inputArr  = null;
            int      goodCount = 0;

            try //Try to read the text file
            {
                inputArr = System.IO.File.ReadAllLines(@"./data/Day7.txt");
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            foreach (string s in inputArr)
            {
                List <string> inside      = InputManipulator.InsideSquareBrackets(s);
                List <string> outside     = InputManipulator.OutsideSquareBrackets(s);
                bool          insideABBA  = false;
                bool          outsideABBA = false;
                foreach (string x in inside) //Check for ABBA inside brackets
                {
                    if (ABBA.ABBACheck(x))
                    {
                        insideABBA = true;
                    }
                }
                foreach (string x in outside) //Check for ABBA outside brackets
                {
                    if (ABBA.ABBACheck(x))
                    {
                        outsideABBA = true;
                    }
                }
                if (!insideABBA && outsideABBA)
                {
                    goodCount++;
                }
            }

            Console.WriteLine("The good IP count (ABBA) is: " + goodCount);


            //Part 2
            int abaCount = 0;

            foreach (string s in inputArr)
            {
                List <string> inside  = InputManipulator.InsideSquareBrackets(s);
                List <string> outside = InputManipulator.OutsideSquareBrackets(s);
                bool          found   = false;

                foreach (string x in outside) //Check for ABBA outside brackets
                {
                    if (ABBA.ABACheck(x))
                    {
                        List <string> abaList = ABBA.GetABAs(x);

                        foreach (string aba in abaList)
                        {
                            foreach (string insideString in inside)
                            {
                                string bab = ABBA.GenerateBAB(aba);
                                if (insideString.Contains(bab))
                                {
                                    found = true;
                                }
                            }
                        }
                    }
                }
                if (found)
                {
                    abaCount++;
                }
            }

            Console.WriteLine("The good IP count (ABA) is: " + abaCount);
        }