Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
fib solution in Clear category for Fibonacci Spiral's End by imloafer
def fib(n):
a, b = 0, 1
yield a
for _ in range(n):
a, b = b, a + b
yield a
def fibo_spiral_end(elem: int) -> list[int]:
# your code here
x, y = 0, 0
for i, fibo in enumerate(fib(elem)):
i = i % 4
if i == 0:
x, y = x - fibo, y - fibo
if i == 1:
x, y = x + fibo, y - fibo
if i == 2:
x, y = x + fibo, y + fibo
if i == 3:
x, y = x - fibo, y + fibo
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. 6, 2023
Comments: