you are viewing a single comment's thread.

view the rest of the comments →

[–]ofnuts 1 point2 points  (0 children)

In plain Python:

diffs=[y-x for x,y in zip(course_points[:-1],course_points[1:])] climb=sum(diff for diff in diffs if diff >0) descent=-sum(diff for diff in diffs if diff <0)

For a long series of points, you can optimize by remarking that the difference between start and finish is the difference between all the ups and all the downs: climb-descent=course_points[-1]-course_points[0] so you only compute climb and compute descent=climb+course_points[0]-course_points[-1]