Skip to content

Instantly share code, notes, and snippets.

@raol
Created October 31, 2013 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raol/7248091 to your computer and use it in GitHub Desktop.
Save raol/7248091 to your computer and use it in GitHub Desktop.
Calculates filled gaps between pikes
def calculate_volume(terrain):
if len(terrain) < 3: return 0
lmax = 0
rmax = 0
left = 0
right = len(terrain) - 1
volume = 0;
while left < right:
if terrain[left] > lmax:
lmax = terrain[left]
if terrain[right] > rmax:
rmax = terrain[right]
if lmax > rmax:
volume += rmax - terrain[right]
right -= 1
else:
volume += lmax - terrain[left]
left += 1
return volume
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment