16 lines
835 B
Markdown
16 lines
835 B
Markdown
|
|
This calls for some explanations.
|
|
solutions_P1.py solves the first part and solutions_P2.py solves the second part.
|
|
|
|
I first started out writing the code in solutions_P2.py but i kept getting the wrong answers.
|
|
Basically I find a zero in the grid, then check up, down, left and right if any of them are
|
|
a one. If any are, call find_path, which looks for two, then three and so on.
|
|
Returns 1 each time a nine is found. This means all valid paths are returned.
|
|
|
|
I decided to read the problem again and started from a fresh solutions_P1.py file.
|
|
The problem can be solved using BFS (Breadth First Search). I implemented a standard BFS
|
|
function in my fred.py helper file.
|
|
Then used that to corrently find the solution.
|
|
|
|
Reading part 2 i realized my first code would be useful and without modifying it, it gave me
|
|
the right answer. |