Beispiel #1
0
        public override object PartOne(string[] input)
        {
            var(coordLines, foldLines) = new SeparatedGroupParser().Parse(input).Two();

            var points = ParseCoordinates(coordLines);

            var folds = ParseFolds(foldLines);

            var folded = DoFold(points, folds[0]);

            Console.Out.WriteLine(folded.AsDefinedSizeNotPreservingCoordinates().Dump());

            return(folded.AllDefinedCells.Count());
        }
Beispiel #2
0
        public override object PartTwo(string[] input)
        {
            var(coordLines, foldLines) = new SeparatedGroupParser().Parse(input).Two();

            var points = ParseCoordinates(coordLines);

            var folds = ParseFolds(foldLines);

            // var folded = DoFold(points, folds[0]);
            var folded = points;

            foreach (var fold in folds)
            {
                folded = DoFold(folded, fold);
            }

            return(folded.AsDefinedSizeNotPreservingCoordinates().Dump());
        }
Beispiel #3
0
        public void ShouldSupportOtherSeparators()
        {
            var input = new[]
            {
                "g1 one",
                "g1 two",
                "g1 three",
                "=====",
                "g2 one",
                "=====",
                "g3 one",
                "g3 two"
            };

            var groups = new SeparatedGroupParser().Parse(input, "=====").Select(x => x.ToList()).ToList();

            groups.Should().HaveCount(3);
            groups[0].Should().Contain("g1 two");
            groups[2].Should().Contain("g3 two");
        }
Beispiel #4
0
        public void ShouldAllowNewlineAtEnd()
        {
            var input = new[]
            {
                "g1 one",
                "g1 two",
                "g1 three",
                "",
                "g2 one",
                "",
                "g3 one",
                "g3 two",
                ""
            };

            var groups = new SeparatedGroupParser().Parse(input).Select(x => x.ToList()).ToList();

            groups.Should().HaveCount(3);
            groups[0].Should().Contain("g1 two");
            groups[2].Should().Contain("g3 two");
        }