Time to check the rest of the slopes — you need to minimize the probability of a sudden arboreal stop, after all.

Determine the number of trees you would encounter if, for each of the following slopes, you start at the top-left corner and traverse the map all the way to the bottom:

Along the same map we used before:

..##.......
#...#...#..
.#....#..#.
..#.#...#.#
.#...##..#.
..#.##.....
.#.#.#....#
.#........#
#.##...#...
#...##....#
.#..#...#.#

these slopes would find 2, 7, 3, 4, and 2 trees respectively.

Assignment

Write a static function countTrees that takes three arguments: i) an integer \(r \in \mathbb{N}_0\) (int), ii) an integer \(d \in \mathbb{N}_0\) (int), and iii) the pathname (String) of a text file containing a map of the open squares (.) and trees (#) on a slope. The function must return the number of trees (int) you would encounter when starting at the top-left corner of the map and following a slope of right \(r\) and down \(d\).

This static function must be located in the class Submission.

Example

In this interactive session we assume the text file slope.txt1 to be located in the current directory.

> Submission.countTrees(1, 1, "slope.txt")
2
> Submission.countTrees(3, 1, "slope.txt")
7
> Submission.countTrees(5, 1, "slope.txt")
3
> Submission.countTrees(7, 1, "slope.txt")
4
> Submission.countTrees(1, 2, "slope.txt")
2