Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Evenly Spaced Trees by Georgyphyton
from typing import List
import math
def evenly_spaced_trees(trees: List[int]) -> int:
nod = math.gcd(*(trees[i+1] - trees[i]for i in range(len(trees)-1)))
return (trees[-1]-trees[0])/nod-len(trees)+1
if __name__ == '__main__':
print("Example:")
print(evenly_spaced_trees([0, 2, 6]))
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!")
Oct. 26, 2023
Comments: