From 601e9f0dd60c9ed3d8c5a57058adafc045a4874a Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 24 Nov 2023 14:33:51 +0100 Subject: [PATCH] vault backup: 2023-11-24 14:33:51 --- Algo/B2/Exercises/Repetitive tutorial.md | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Algo/B2/Exercises/Repetitive tutorial.md b/Algo/B2/Exercises/Repetitive tutorial.md index 59f9ef5..f3469d5 100644 --- a/Algo/B2/Exercises/Repetitive tutorial.md +++ b/Algo/B2/Exercises/Repetitive tutorial.md @@ -76,17 +76,15 @@ def power(x, n): ## Exercise 1.4 ```python -def fibo(n: int) -> int: - a = 0 - b = 1 - c = 0 - i = 2 - while i <= n: - c = a + b - a = b - b = c - i += 1 - return b +def fibo(n): + prev = 1 #f0 + cur = 1 #f1 + while n> 1: + (prev, cur) = (cur, prev+cur) + n -= 1 + return cur +# OR + ``` ## Exercise 1.5