19
1
Given the topography of land in ASCII picture format, figure out where lakes would go and fill them in. Assume an infinite amount of rain.
example
input
#
##
# ####
# #########
## ###########
## ############# ####
## ############## #####
################# #######
#########################
#########################
output
#
##
#@####
#@@@@#########
##@@###########
##@#############@@@####
##@##############@@#####
#################@#######
#########################
#########################
The input will contain only spaces and # marks. Each line will be the same length. The output should be the identical # pattern with spaces where water would accumulate filled in with @ marks.
The bottom input row will always be all # marks. There will be no holes or overhangs in the land. Shortest code wins.
This seems a bit easy. I think we should also have to display the number of lake units
@that were filled in. – mellamokb – 2011-05-12T20:53:26.9271@mellamokb: This would be roughly a
([char[]]"$a"-eq'@').Counthere. Not that much too add. Agreed on this being a little too easy, though. Doesn't fall into the realm of what I'd downvote, though. – Joey – 2011-05-12T20:55:41.9003
Related on Stack Overflow: Code Golf: Running Water. One of LiraNuna's better one, I thought.
– dmckee --- ex-moderator kitten – 2011-05-12T21:41:20.0331So do we also have to handle underground caverns, which may have air above the water level like the Running Water puzzle? That makes things a little more challenging and I think should definitely be an example use case. – mellamokb – 2011-05-12T21:45:51.200
@dmckee: That one wasn't as easy as this though. – Joey – 2011-05-12T21:45:58.110
@mellamokb: I think we agreed some time ago that the questions from SO are not to be replicated here. Mostly because there are already solutions there. – Joey – 2011-05-12T21:48:22.617
@joey: No. The possibility of the caves seems to rule our a simple regexp solution to the LiraNuna one. – dmckee --- ex-moderator kitten – 2011-05-12T21:52:43.297
Since # and @ are both massive characters, I suggest using . instead of @, which gives better pictures, IMHO. – user unknown – 2011-05-13T13:52:18.367