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 peshikovs
from typing import List
from math import gcd
import operator
def evenly_spaced_trees(trees: List[int]) -> int:
return len(range(trees[0], trees[-1]+1, gcd(*map(lambda x: x[1]-x[0], zip(trees, trees[1:]))))) - len(trees)
if __name__ == '__main__':
print("Example:")
print(evenly_spaced_trees([27,29,53,75]))
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!")
Jan. 24, 2023