Water Towers

Challenge: Water between Towers

In a two-dimensional world, we begin with a bar-chart, or rows of unit-width 'towers' of arbitrary height. Then it rains, completely filling all convex enclosures in the chart with water.

9        █       
8        █           
7   █    █          
6   █ █  █           
5 █ █ █ ██      
4 █ █ ████      
3 ███ ████     
2 ████████ █ 
1 ██████████ 
9        █    
8        █    
7   █≈≈≈≈█    
6   █≈█≈≈█    
5 █≈█≈█≈██    
4 █≈█≈████    
3 ███≈████    
2 ████████≈█
1 ██████████

Your task for this challenge is to write a generator water-towers. It will take as input a (list @ud), with each number representing the height of a tower from left to right. It will output a @ud representing the units of water that can be contained within the structure.

Example usage:

Unit Tests

Following a principle of test-driven development, we compose a series of tests which allow us to rigorously check for expected behavior.

Solutions

These solutions were submitted by the Urbit community as part of a competition in ~2023.6. They are made available under the MIT License and CC0. We ask you to acknowledge authorship should you utilize these elsewhere.

Solution #1

By ~dannul-bortux. A model for literate programming in Hoon.

Solution #2

By ~racfer-hattes. A short and elegant solution.

Solution #3

By ~dozreg-toplud. Another very literate and clean solution.

Last updated