Happy !
zeroflag / TrappingRainWater
About TrappingRainWater
Trapping rain between towers
This is a solution of the following problem:
You are given an input array whose each element represents the height of a line towers. The width of every tower is 1. It starts raining. How much water is collected between the towers?
This solution is neither clever nor fast. This is the usual boring algorithm what usually people use to solve this problem. What is interesting about it is the visualization made by Roassal (and how it helps while coding each steps of the solution).
Loading project
Gofer it
smalltalkhubUser: 'zeroflag' project: 'TrappingRainWater';
configuration;
loadDevelopment.
Usage
Enter this into the Playground and click "Do it all and go".
towers := Towers heights: #(5 3 7 2 6 4 5 9 1 2).
Now add some water.
towers rainfall.
Get the amount of water trapped between the towers.
towers trappedWater.
