Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Fibonacci Spiral's End by freeman_lex
from itertools import cycle
def fibo_spiral_end(elem: int) -> list[int]:
x = y = 0
f0, f1 = 0, 1
for _, (dx, dy) in zip(range(elem), cycle("+- ++ -+ --".split())):
x, y = eval(f"{x}{dx}{f1}, {y}{dy}{f1}")
f0, f1 = f1, f0 + f1
return [x, y]
print("Example:")
print(fibo_spiral_end(5))
# These "asserts" are used for self-checking
assert fibo_spiral_end(0) == [0, 0]
assert fibo_spiral_end(1) == [1, -1]
assert fibo_spiral_end(2) == [2, 0]
assert fibo_spiral_end(3) == [0, 2]
assert fibo_spiral_end(4) == [-3, -1]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Jan. 5, 2023
Comments: