Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Mountain Scape by biorockstar
def mountain_scape(tops):
result = set()
for x, w in tops:
# For each triangle, create sets of (point, height at that point)
ascending = { (x + i, w + i) for i in range(-w, 1, 1) }
descending = { (x + j, w - j) for j in range(w, -1, -1) }
result = result.union(ascending, descending)
# Will be cases of multiple heights reported for a single point. Use max() height only.
result = set( (i, max(j for q, j in result if q == i)) for i, _ in result )
return sum(j for _, j in result)
if __name__ == '__main__':
print("Example:")
print(mountain_scape([(1, 1), (4, 2), (7, 3)]))
print(mountain_scape([(1,3),(5,3),(5,5),(8,4)]))
print(mountain_scape([(0,2),(5,3),(7,5)]))
print(mountain_scape([[3,3],[5,3],[7,3],[9,3],[11,3],[13,3],[15,3],[17,3],[19,3],[21,3]]))
# These "asserts" are used for self-checking and not for an auto-testing
assert mountain_scape([(1, 1), (4, 2), (7, 3)]) == 13
assert mountain_scape([(0, 2), (5, 3), (7, 5)]) == 29
assert mountain_scape([(1, 3), (5, 3), (5, 5), (8, 4)]) == 37
print("Coding complete? Click 'Check' to earn cool rewards!")
Jan. 3, 2023