You are given an n \times n grid where some squares contain a coin.
In one step, you can collect all the coins from a row or a column of your choice. What is the smallest number of steps needed to collect all the coins?
In the grid description, the character .
means an empty square and X
means a coin. You may assume that 1 \le n \le 20.
In a file coingrid.py
, implement a function count
that returns the smallest number of steps to collect all coins.
def count(r): # TODO if __name__ == "__main__": r =["........", "........", "...X..X.", "........", "....X...", "..X.X..X", "........", "....X..."] print(count(r)) # 3