Skip to content
Snippets Groups Projects
Commit ee4c4ff3 authored by Michael Mutote's avatar Michael Mutote
Browse files

22202956

Exercise 4.9 question 3 done.

Optimised and removed a lot of un-needed code. Might still need to use Dijkstra’s Algorithm
parent 124d79d3
No related branches found
No related tags found
No related merge requests found
def nsp(x, y, current=(0, 0)):
if current is None:
def nsp(x, y):
if x < 0 or y < 0:
return 0
if current == (x, y):
if (0, 0) == (x, y):
return 1
else:
next_corner = new_index(x, y, current)
# uses helper function to find the next corner
return nsp(x, y, next_corner[0]) + nsp(x, y, next_corner[1])
pass
return nsp(x, y - 1) + nsp(x - 1, y)
def new_index(x, y, current):
# Helper function to find the possible next states, reduced clutter
if current[0] < x and current[1] < y:
return (current[0], current[1] + 1), (current[0] + 1, current[1])
if current[0] >= x and current[1] < y:
return (current[0], current[1] + 1), None
if current[0] < x and current[1] >= y:
return (current[0] + 1, current[1]), None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment