예제 #1
0
        private static int GetTreeCount(SlopeMap map, int stepX, int stepY)
        {
            var treeCount = 0;

            var x = 0;
            var y = 0;

            while (y < map.MapHeight)
            {
                if (map.GetGeologyForCoordinate(x, y) == MapGeology.Tree)
                {
                    treeCount++;
                }

                x += stepX;
                if (x > map.MapWidth - 1)
                {
                    x -= map.MapWidth;
                }

                y += stepY;
            }

            return(treeCount);
        }
예제 #2
0
        public static int Third2(List <string> input)
        {
            var map = new SlopeMap(input);

            var instructions = new List <Tuple <int, int> >
            {
                new Tuple <int, int>(1, 1),
                new Tuple <int, int>(3, 1),
                new Tuple <int, int>(5, 1),
                new Tuple <int, int>(7, 1),
                new Tuple <int, int>(1, 2),
            };

            var result = 1;

            foreach (var instruction in instructions)
            {
                result = result * GetTreeCount(map, instruction.Item1, instruction.Item2);
            }

            return(result);
        }
예제 #3
0
        public static int Third1(List <string> input)
        {
            var map = new SlopeMap(input);

            return(GetTreeCount(map, 3, 1));
        }