Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Evenly Spaced Trees by vvm70
from typing import List
import math
def evenly_spaced_trees(trees: List[int]) -> int:
spans = [x - y for x, y in zip(trees[1:], trees[:-1])]
gcd = spans[0]
for i in spans[1:]:
gcd = math.gcd(gcd, i)
return len(range(trees[0], trees[-1] + 1, gcd)) - len(trees)
if __name__ == '__main__':
print("Example:")
print(evenly_spaced_trees([0, 2, 6]))
print(evenly_spaced_trees([10, 58, 64, 82, 91]))
assert evenly_spaced_trees([0, 2, 6]) == 1, 'add 1'
assert evenly_spaced_trees([1, 3, 6]) == 3, 'add 3'
assert evenly_spaced_trees([0, 2, 4]) == 0, 'no add'
print("Coding complete? Click 'Check' to earn cool rewards!")
July 15, 2020