title: Code Golf: Running Water
body: <h2>The challenge</h2>
  
  <p>The shortest code by character count to identify and mark water depressions in the ASCII representation of a land from input.</p>
  
  <p>Input will be an ASCII representation of a landscape, having hills, valleys and flat lands. The program should simulate what the landscape would look like if if was flooded - filling all valleys with water (character <code>x</code>). </p>
  
  <p>The landscape will always start and stop with the character <code>_</code> and will be at least 2 characters long, making the shortest input <code>__</code>.</p>
  
  <p>A hill is defined as a raise, and should not be filled with water:</p>
  
  <pre><code>  __
  _/  \_
  </code></pre>
  
  <p>A valley is defined as a depression and will be filled with water until a flatland is encountered:</p>
  
  <pre><code>_    _
   \__/
  </code></pre>
  
  <p>Input can be assumed clean and will be composed only from the characters space (<code></code>), newline (<code>\n</code>), underscore (<code>_</code>), and forward and backward slashes (<code>/</code> and <code>\</code>). Input can be seen as a continuous line, and any input that contains ambiguous line input such as <code>_/_</code> or</p>
  
  <pre><code>_   _
   \_/
   / \
  </code></pre>
  
  <p>Is considered invalid.</p>
  
  <p>Regarding underwater caves, water level should be maintained if cave level goes above water level.</p>
  
  <h2>Test cases</h2>
  
  <pre><code>Input:
      __/\__
            \__              
               \       ___       ___________
               /      /   \_     \_
               \_____/      \__  _/
                               \/
  Output:
  
      __/\__
            \__              
               \       ___       ___________
               /xxxxxx/   \xxxxxx\_
               \xxxxx/      \xxxxx/
                               \/
  </code></pre>
  
  <hr>
  
  <pre><code>Input:
                                           __       ___
                                          /  \_____/
                                         / _______
                           ________     /  \     /
                     _____/        \   /__  \    \_
      ____          /               \    /__/   __/
          \_       /                 \     ____/
            \______\                 /____/
  
  Output:
                                           __       ___
                                          /  \xxxxx/
                                         / _______
                           ________     /  \     /
                     _____/        \xxx/__  \xxxx\_
      ____          /               \xxxx/__/xxxxx/
          \xxxxxxxx/                 \xxxxxxxxx/
            \xxxxxx\                 /xxxx/
  </code></pre>
  
  <hr>
  
  <pre><code>Input:
                                                        __     _
      _       ____                    ____        _____/  \   /
       \     /    \        __________/    \    __/  ___   /___\
        \___/      \       \               \   \___/  /_
                   /________\               \___________\
  
  Output:
                                                        __     _
      _       ____                    ____        _____/  \xxx/
       \xxxxx/    \xxxxxxxxxxxxxxxxxx/    \xxxxxx/  ___   /xxx\
        \xxx/      \xxxxxxx\               \xxx\___/xx/_
                   /xxxxxxxx\               \xxxxxxxxxxx\
  </code></pre>
  
  <p>Code count includes input/output (i.e full program).</p>