Пример #1
0
        public void ShouldReturnEmptyRegexForEmptyButValidRegexInput()
        {
            // arrange
            string input = "^$";

            // act
            IRegex result = Parser.Parse(input);

            // assert
            Assert.AreEqual(string.Empty, result.GetLongestNonCyclicWord());
        }
Пример #2
0
        public void ShouldReturnValueForComplexBranches()
        {
            // arrange
            const string expected = "WSSEESWWWNWNENNEEEENNESSSSWNWSW";
            string       input    = $"^WSSEESWWWNW(S|NENNEEEENN(ESSSSW(NWSW|SSEN)|WSWWN(E|WWS(E|SS))))$";

            // act
            IRegex result = Parser.Parse(input);

            // assert
            Assert.AreEqual(expected, result.GetLongestNonCyclicWord());
        }
Пример #3
0
        public void ShouldReturnValueForOneBranch()
        {
            // arrange
            const string expected = "SNTRE";
            string       input    = $"^SN(E|TRE)$";

            // act
            IRegex result = Parser.Parse(input);

            // assert
            Assert.AreEqual(expected, result.GetLongestNonCyclicWord());
        }
Пример #4
0
        public void ShouldReturnResultForThreeCharacterInput()
        {
            // arrange
            const string expecteResult = "SNW";
            string       input         = $"^{expecteResult}$";

            // act
            IRegex result = Parser.Parse(input);

            // assert
            Assert.AreEqual(expecteResult, result.GetLongestNonCyclicWord());
        }
Пример #5
0
        public void ShouldReturnValueForComplexBranchesWithOptional()
        {
            // arrange
            const string expected = "ESSWWNNNENNWWWSSSSENNNE";
            string       input    = $"^ESSWWN(E|NNENN(EESS(WNSE|)SSS|WWWSSSSE(SW|NNNE)))$";

            // act
            IRegex result = Parser.Parse(input);

            // assert
            Assert.AreEqual(expected, result.GetLongestNonCyclicWord());
        }
Пример #6
0
        static void Main(string[] args)
        {
            string filename = args[0];
            string input    = File.ReadAllText(filename);

            IRegex regex = Parser.Parse(input);

            Console.WriteLine($"Part1: {regex.GetLongestNonCyclicWord().Length}");

            HashSet <string> validPaths = new HashSet <string>();
            HashSet <string> allPaths   = regex.GetNonCyclicWords().ToHashSet();

            foreach (var path in allPaths)
            {
                for (int i = 1000; i <= path.Length; i++)
                {
                    validPaths.Add(path.Substring(0, i));
                }
            }
            Console.WriteLine(validPaths.Count());
            Console.WriteLine(validPaths.Select(GetRoomCoordinates).ToHashSet().Count());
        }