btholt / btholt/algorithms-exercises

Bug with pathfinding solution

Open
#26 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
253
Forks
834
PR merge metrics
No merged PRs in 30d

Description

I think there is a bug with the pathfinding solution where it doesn't get neighbors correctly when the grid isn't square. https://github.com/btholt/algorithms-exercises/blob/5b2edb0bc08e033d552ea7f9c891d02b49863aa0/specs/pathfinding/pathfinding.solution.test.js#L77

` if (y - 1 >= 0 && !visited[y - 1][x].closed) {` is up
and ln 85 ` if (y + 1 < visited[0].length && !visited[y + 1][x].closed) {` is down. Since we move up and down ln 85 should check `visited.length` not `visited[0].length` else it can run out of bounds with non square (rectangular) grids. Conversely ln 95 should be flipped to check `visited[0].length` since that is left and right and the nested arrays represent Xs max size.

I'm enjoying the course. Thanks!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.