From 9528fd70dbb4e399e4b1088f588321cb091641c9 Mon Sep 17 00:00:00 2001 From: Michael Mutote <130656746+mr1Michael@users.noreply.github.com> Date: Wed, 18 Oct 2023 11:20:59 +0200 Subject: [PATCH] 22202956 Exercise 4.9 question 4 done still requires optimization for space usage and speed. Memoizing might be a good Idea! --- 4_9_Exercises/Question 4.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/4_9_Exercises/Question 4.py b/4_9_Exercises/Question 4.py index b5a7132..447be83 100644 --- a/4_9_Exercises/Question 4.py +++ b/4_9_Exercises/Question 4.py @@ -7,12 +7,13 @@ def np(x, y, trace=None): if current[0] > x or current[1] > y or current[0] < 0 or current[1] < 0: return 0 if (current[0], current[1]) == (x, y) and len(trace) > 1: - print(current[0], x, current[1], y, " this is in success") - print(trace) + # print(current[0], x, current[1], y, " this is in success") + # print(trace) return 1 if x + y < 2: return 1 - + # if (x, y) in new_cache: + # return new_cache[(x, y)] x_1, y_1 = (current[0], current[1] + 1) if current[1] < y else (current[0], current[1]) x_2, y_2 = (current[0] + 1, current[1]) if current[0] < x else (current[0], current[1]) x_3, y_3 = current[0] - 1, current[1] -- GitLab