title: Solving Twitter Puddle with Zipper
body: <p>This is a follow-up to my previous <a href="https://stackoverflow.com/questions/23984160/zipper-to-iterate-over-list-in-scala">question</a>. Consider the following <a href="http://programmingpraxis.com/2013/11/15/twitter-puddle/" rel="nofollow noreferrer">puzzle</a></p>
  
  <p>I would like to generate a <code>waterLevel</code> array, so that the i-th item is the water level at the i-th point and then sum them up to solve the puzzle.</p>
  
  <pre><code>waterLevel[i] =
    max(0, min(max of left neighbors, max of right neighbors) - height[i])
  </code></pre>
  
  <p>I would probably try to code it with <code>Zipper</code></p>
  
  <pre><code> waterLevels = heights.toZipper.cobind {z =&gt; 
     max(0, min(max(z.left), max(z.right)) - z.focus
   }.toList
  </code></pre>
  
  <p>Does it make sense ?</p>