A task
The shortest code by number of characters to identify and mark water depressions in the ASCII view of the land from the entrance.
The input will be an ASCII representation of a landscape with hills, valleys and flat lands. The program should imitate what the landscape would look like if it were flooded - filling all the valleys with water (symbol x ).
The landscape will always start and stop with the symbol _ and will contain at least 2 characters, making the shortest input __ .
A hill is defined as rising and should not be filled with water:
__ _/ \_
The valley is defined as depression and is filled with water until a flat surface meets:
_ _ \__/
Input can be considered clean and will consist only of a character space ( ), newline ( \n ), underscore ( _ ), and forward and backward slashes ( / and \ ). An input can be thought of as a continuous line, and any input containing ambiguous line inputs, such as _/_ or
_ _ \_/ / \
It is considered invalid.
For underwater caves, the water level should be maintained if the cave level exceeds the water level.
Test cases
Input: __/\__ \__ \ ___ ___________ / / \_ \_ \_____/ \__ _/ \/ Output: __/\__ \__ \ ___ ___________ /xxxxxx/ \xxxxxx\_ \xxxxx/ \xxxxx/ \/
Input: __ ___ / \_____/ / _______ ________ / \ / _____/ \ /__ \ \_ ____ / \ /__/ __/ \_ / \ ____/ \______\ /____/ Output: __ ___ / \xxxxx/ / _______ ________ / \ / _____/ \xxx/__ \xxxx\_ ____ / \xxxx/__/xxxxx/ \xxxxxxxx/ \xxxxxxxxx/ \xxxxxx\ /xxxx/
Input: __ _ _ ____ ____ _____/ \ / \ / \ __________/ \ __/ ___ /___\ \___/ \ \ \ \___/ /_ /________\ \___________\ Output: __ _ _ ____ ____ _____/ \xxx/ \xxxxx/ \xxxxxxxxxxxxxxxxxx/ \xxxxxx/ ___ /xxx\ \xxx/ \xxxxxxx\ \xxx\___/xx/_ /xxxxxxxx\ \xxxxxxxxxxx\
The number of codes includes input / output (i.e., a complete program).
language-agnostic code-golf rosetta-stone
LiraNuna Nov 19 '09 at 21:24 2009-11-19 21:24
source share