Beispiel #1
0
        public static void Main()
        {
            var lines = System.IO.File.ReadAllLines(@".\sampleData2.txt");

            var reult = new Pyramid(lines).FindPath();

            Console.WriteLine(reult);
        }
Beispiel #2
0
        public void Should_Find_Path_With_Single_Parent_Node()
        {
            var input = new[]
            {
                "1 4 21"
            };
            var pyramid = new Pyramid(input);

            var result = pyramid.FindPath();

            result.Nodes.Should().BeEquivalentTo(new[] { 1 });
        }
Beispiel #3
0
        public void Should_Find_Path_When_Root_Node_Has_Multiple_Values()
        {
            var input = new[]
            {
                "51 4 21",
                "1 10 11 3",
                "1 21 19 3 5"
            };
            var pyramid = new Pyramid(input);

            var result = pyramid.FindPath();

            result.Nodes.Should().BeEquivalentTo(new[] { 51, 10, 21 });
        }
Beispiel #4
0
        public void Should_Find_Path_When_Comparing_Even_Numbers()
        {
            var input = new[]
            {
                "1",
                "8 10",
                "9 5 3",
                "14 10 2 12"
            };
            var pyramid = new Pyramid(input);

            var result = pyramid.FindPath();

            result.Nodes.Should().BeEquivalentTo(new[] { 1, 8, 9, 14 });
        }
Beispiel #5
0
        public void Should_Find_Leftmost_Path()
        {
            var input = new[]
            {
                "1",
                "8 9",
                "11 5 9",
                "4 5 2 3"
            };
            var pyramid = new Pyramid(input);

            var result = pyramid.FindPath();

            result.Nodes.Should().BeEquivalentTo(new[] { 1, 8, 11, 4 });
        }
Beispiel #6
0
        public void Should_Find_Rightmost_Path()
        {
            var input = new[]
            {
                "1",
                "8 10",
                "9 5 11",
                "14 5 2 12"
            };
            var pyramid = new Pyramid(input);

            var result = pyramid.FindPath();

            result.Nodes.Should().BeEquivalentTo(new[] { 1, 10, 11, 12 });
        }
Beispiel #7
0
        public void Should_Find_Path_With_Negative_Values()
        {
            var input = new[]
            {
                "-1",
                "-8 9",
                "5 -9 9",
                "1 -10 11 3",
                "1 21 19 3 5"
            };
            var pyramid = new Pyramid(input);

            var result = pyramid.FindPath();

            result.Nodes.Should().BeEquivalentTo(new[] { -1, -8, 5, -10, 21 });
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            var lines = GetPyramidLines(Input1);

            Console.WriteLine("Input: ");
            foreach (var line in lines)
            {
                Console.WriteLine(line);
            }

            var tree = new Pyramid(lines);

            tree.Calculate();

            Console.WriteLine(string.Empty);
            Console.WriteLine("Max sum: " + tree.Max);
            Console.WriteLine($"Path: {string.Join(", ", tree.MaxPath)}");

            Console.ReadKey();
        }
Beispiel #9
0
        public void Should_Find_Path_For_SampleData3()
        {
            var r = new Pyramid(File.ReadAllLines(@".\sampleData3.txt")).FindPath();

            r.Sum.Should().Be(26);
        }