Programming puzzle

In your favorite language, write a program that takes a list/array of numbers which corresponds to a bar chart, where water can fill any gaps in the bars. Calculate the total area/units of water (bars are integers).

Water drains off left and right sides, and an array value of zero is a bottom hole that also drains water.

Pic related demonstrates concept.

Attached: water_bars.jpg (231x271, 14K)

Other urls found in this thread:

pastebin.com/4mbhSLzd
twitter.com/SFWRedditImages

how can a single list of numbers correspond to the chart?

also none of the bars in your picture have gaps

one axis is index and other axis is values

and you've just failed this job interview

What if i have [1,5,1,5,1,5,1] ?

Anyways, i guess something like this would work:

>Asume first number in array is the biggest number
>Initialize total as 0
>For each element in the array
>if number is bigger than our biggest number, change biggest number to this number
>if not, calculate biggest number - number, and add it up to total
>if number is 0 or below, set total to 0

>array
>axis
Not sure if I want a job where the superiors have no idea how to say "jagged array".

Just give the real assignement, if you want us to do your homework go to /sqt/ and give every info.

>Water drains off left and right sides, and an array value of zero is a bottom hole that also drains water.
Is there a trick or something? Would vector 2 1 2 0 contain water between twos? Would vector 2 1 4 1 3 contain 2 different water levels?

Complain instead of trying to give a solution.

Way to go Jow Forums

>give poorly-formed question lacking information
>complain you don't get instant answers to your highschool intro to programming homework

blow me