Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
reduce via gcd to calculate interval between trees solution in Clear category for Evenly Spaced Trees by Leonix
import functools, math
def evenly_spaced_trees(trees):
distances = (abs(a - b) for a, b in zip(trees[:-1], trees[1:]))
interval = functools.reduce(math.gcd, distances, next(distances))
return len(set(range(trees[0], trees[-1], interval)) - set(trees))
April 9, 2019
Comments: