From e1e32c73f34df03c34c2f4e668c69134ed603d2a Mon Sep 17 00:00:00 2001 From: Craig D'Silva Date: Fri, 26 Jun 2026 22:04:45 +0100 Subject: [PATCH 1/3] Fibonacci --- Sprint-2/improve_with_caches/fibonacci/fibonacci.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-2/improve_with_caches/fibonacci/fibonacci.py b/Sprint-2/improve_with_caches/fibonacci/fibonacci.py index 60cc6671..90c196f6 100644 --- a/Sprint-2/improve_with_caches/fibonacci/fibonacci.py +++ b/Sprint-2/improve_with_caches/fibonacci/fibonacci.py @@ -1,4 +1,9 @@ def fibonacci(n): if n <= 1: return n - return fibonacci(n - 1) + fibonacci(n - 2) + nums = [0, 1] + i = 0 + while i < n: + nums.append(nums[len(nums) - 1] + nums[len(nums) - 2]) + i += 1 + return nums[n] From 43346333331b8ddee66f820c01eb4d2258f140c0 Mon Sep 17 00:00:00 2001 From: Craig D'Silva Date: Tue, 30 Jun 2026 12:02:09 +0100 Subject: [PATCH 2/3] making_change --- .../making_change/making_change.py | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Sprint-2/improve_with_caches/making_change/making_change.py b/Sprint-2/improve_with_caches/making_change/making_change.py index 255612e5..b25d83d9 100644 --- a/Sprint-2/improve_with_caches/making_change/making_change.py +++ b/Sprint-2/improve_with_caches/making_change/making_change.py @@ -16,17 +16,12 @@ def ways_to_make_change_helper(total: int, coins: List[int]) -> int: """ if total == 0 or len(coins) == 0: return 0 - - ways = 0 - for coin_index in range(len(coins)): - coin = coins[coin_index] - count_of_coin = 1 - while coin * count_of_coin <= total: - total_from_coins = coin * count_of_coin - if total_from_coins == total: - ways += 1 - else: - intermediate = ways_to_make_change_helper(total - total_from_coins, coins=coins[coin_index+1:]) - ways += intermediate - count_of_coin += 1 - return ways + + ways = [0] * (total + 1) + ways[0] = 1 + + for coin in coins: + for amount in range(coin, total + 1): + ways[amount] += ways[amount - coin] + + return ways[total] From a51fe8706ee5a44dddce99be8f96a0a766023d7e Mon Sep 17 00:00:00 2001 From: Craig D'Silva Date: Tue, 30 Jun 2026 14:04:41 +0100 Subject: [PATCH 3/3] Remove unecessary code --- Sprint-2/improve_with_caches/making_change/making_change.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Sprint-2/improve_with_caches/making_change/making_change.py b/Sprint-2/improve_with_caches/making_change/making_change.py index b25d83d9..c77af0f1 100644 --- a/Sprint-2/improve_with_caches/making_change/making_change.py +++ b/Sprint-2/improve_with_caches/making_change/making_change.py @@ -13,10 +13,7 @@ def ways_to_make_change(total: int) -> int: def ways_to_make_change_helper(total: int, coins: List[int]) -> int: """ Helper function for ways_to_make_change to avoid exposing the coins parameter to callers. - """ - if total == 0 or len(coins) == 0: - return 0 - + """ ways = [0] * (total + 1) ways[0] = 1