You must walk in an n \times n grid from the top left corner to the bottom right corner so that in each round you move one step right or down. What is the smallest number of monsters you encounter if you choose your route optimally?
In the description of the grid, the character .
represents floor, the character #
represents wall and the character @
represents a monster. You may assume that 1 \le n \le 20. If there is no route, the answer should be −1.
In a file monsters.py
, implement a function count
that returns the smallest number of monsters.
def count(r): # TODO if __name__ == "__main__": r = ["....@", "@##.#", ".##@#", ".@..#", "###@."] print(count(r)) # 2