コード例 #1
0
        public int CalculateTreesHit(string filePath, Slope slope)
        {
            List <char[]> map      = FileUtility.ParseFileToList(filePath, line => line.ToCharArray());
            int           treesHit = 0;

            // Our current pointers
            int currentRow = 0;
            int currentCol = 0;
            int mapWidth   = map.First().Length;

            // Loop through the map and determine if we hit a tree
            do
            {
                char location = map[currentRow][currentCol];

                if (location == '#')
                {
                    treesHit++;
                }

                // Move right, including wrap around
                currentCol += slope.Right;
                if (currentCol >= mapWidth)
                {
                    currentCol = currentCol % mapWidth;
                }

                // Move down
                currentRow += slope.Down;
            } while (currentRow < map.Count);

            return(treesHit);
        }
コード例 #2
0
        public string PartA()
        {
            string filePath = @"Three\DayThreeInput.txt";
            Slope  slope    = new Slope(1, 3);

            int treesHit = CalculateTreesHit(filePath, slope);

            return(treesHit.ToString());
        }