Water spread simulation
Your task
A plant nursery waters its growing beds from a single valve. The bench layout arrives as a rectangular grid of one character plots: '.' is a level plot that water runs across, '#' is a raised ridge that water cannot get over, and 'D' is a soak away pit that takes water in but never passes any on. Water enters the plot at valve_row and valve_col, then reaches any plot that shares an edge with a plot already wet. Diagonals do not count, since the ridges run corner to corner. Return how many plots end up wet, including the plot the valve sits on. Return 0 when the valve sits outside the layout or on a ridge, because then nothing is watered. A layout with no rows returns 0. Every row has the same width.
Examples
wet_plot_count(layout: list[list[str]], valve_row: int, valve_col: int) -> intExample 1
Input
wet_plot_count([[".", ".", ".", "."], [".", "#", "#", "."], [".", ".", ".", "."]], 0, 0)Output
10Example 2
Input
wet_plot_count([[".", "D", "."]], 0, 0)Output
2Example 3
Input
wet_plot_count([[".", "#", "."], ["#", "#", "#"], [".", ".", "."]], 0, 0)Output
1