The one-dimensional version of this problem was pretty easy, so here's a harder 2D version.
You are given a 2D array of land heights on standard input, and you have to figure out where the lakes will form when it rains. The height map is just a rectangular array of the numbers 0-9, inclusive.
8888888888
5664303498
6485322898
5675373666
7875555787
You must output the same array, replacing all locations that would be underwater with *
.
8888888888
566*****98
6*85***898
5675*7*666
7875555787
Water can escape diagonally, so there would be no lake in this configuration:
888
838
388
shortest code wins. Your code must handle sizes up to 80 wide and 24 high.
Three more examples:
77777 77777
75657 7*6*7
75757 => 7*7*7
77677 77677
77477 77477
599999 599999
933339 9****9
936639 => 9*66*9
935539 9*55*9
932109 9****9
999999 999999
88888888 88888888
84482288 8**8**88
84452233 => 8**5**33
84482288 8**8**88
88888888 88888888