A dog is leashed to a pole and the owner wants to know if it can venture to the neighbour's building. You're given a map, which contains the pole (represented by x
), the owner's buildings (represented by 1
) and the neighbour's building (represented by 2
). Empty areas are padded with dots and every line has the same length. EDIT: I forgot to mention, neighbour is always to the right from the dog. Every tile represents an area of one square meter. You're also given the length of the dog's leash (as meters). The pole is at the center of the tile. For input you must use the STDIN (and respectively STDOUT for output), if it's available in your language. Otherwise create a function, which takes the input as parameters and returns the answer. An example input to the STDIN would look like this.
6
............
...11..222..
...11..222..
...11.......
.x.11.......
............
Additional newline is guaranteed after the input. The program should output Yes
if the dog can reach the neighbour's building and otherwise No
.
Assumptions
- There can be several buildings belonging to the owner.
- There can only be one neighbour's building.
- The dog can't venture outside the map or through the buildings.
- The dog can't be trapped inside a building.
- The length of the leash is always an integer
- Distances are calculated in Euclidean metric.
This is a codegolf, shortest code wins.
Test cases
Input:
6
............
...11..222..
...11..222..
...11.......
.x.11.......
............
Output: No
Input:
7
............
...11..222..
...11..222..
...11.......
.x.11.......
............
Output: Yes
Input:
7
........
...11...
..111.22
..111.22
.x111.22
..111.22
..111...
Output: No
Input:
8
........
...11...
..111.22
..111.22
.x111.22
..111.22
..111...
Output: Yes