Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
all() in one line solution in Clear category for Escher Symmetry by mu_py
def is_figure(data: list[int]) -> bool:
"""
check, if given figure is an Escher profil
"""
return all(data[0]+data[-1] == data[i]+data[-i-1] for i in range(1, len(data)//2 +1 ))
# we only need to check half of all sums: len()//2, because summation is symmetric
# but we have to take care of uneven lengths, that's why: len()//2 +1
print("Example:")
print(is_figure([1, 2, 1, 2]))
# These "asserts" are used for self-checking
assert is_figure([1, 2, 1, 2]) == True
assert is_figure([1, 3, 2, 1, 3]) == True
assert is_figure([1, 2, 2, 1]) == False
assert is_figure([4, 4, 4, 4, 4, 4, 4, 4, 4]) == True
#just two more checks
assert is_figure([1, 2, 3]) == True
assert is_figure([1, 2, 1]) == False
print("The mission is done! Click 'Check Solution' to earn rewards!")
Oct. 14, 2024