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

22202956

Exercise 4.9 question 3 done.

Works okay for smaller grids but is a lot slower for larger grids. Might be worthwhile to use Dijkstra’s Algorithm
parent db58c4e8
No related branches found
No related tags found
No related merge requests found
def nsp(x, y, current=(0, 0)):
if current is None:
return 0
if current == (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
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