Skip to main content
15 votes
Accepted

Find the correct path through a 5 x 5 grid (coderbyte 'Correct path')

Unnecessary Import numpy is not required for this challenge. You are using none of its special capabilities. The following: ...
AJNeufeld's user avatar
  • 35.3k
13 votes
Accepted

Python program to find a word ladder transforming "four" to "five"

By performing recursion, you are performing a depth-first search of four-letter words. However, this task involves finding a shortest path, and shortest-path problems are generally better done using ...
200_success's user avatar
12 votes

Bellman-Ford optimisation in C

for (uint _ = 0; _ < nb_nodes - 1; _++) Maybe this was python code translated into C?!? Repect the norms of the community. Even though ...
J_H's user avatar
  • 42.2k
10 votes

Dijkstra path finding in C# is 15x slower than C++ version

More speed for both C++ and C# Revisiting an older question. While reading this question and its already very good answers the ...
Oliver Schönrock's user avatar
9 votes
Accepted

Graph puzzle resolver

...
Peter Taylor's user avatar
  • 24.5k
9 votes
Accepted

Implementation of A* algorithm in C++

Euclidean distance is used to calcualte the cost from current node to goal The code implements Manhattan distance, so the comment is wrong, or perhaps the code is wrong, but in any case it doesn't ...
user555045's user avatar
  • 12.4k
9 votes

Optimizing Python BFS Code

I have only a couple of nitpicks: Nitpick 1 while len(queue) > 0: You can write just as: while queue: Nitpick 2 Instead of ...
coderodde's user avatar
  • 32k
9 votes

Faux Random Maze Generator

Overview There is a lot to like about this code: Most of the code is well laid out, with consistent indentation and spacing. The functions and most of the variables have meaningful names. The ...
toolic's user avatar
  • 15.8k
8 votes
Accepted

A* Algorithm in C# for pathfinding 2D tile grid

There is a lot of code here, so there is a lot to say; no way I'll covered everything! I'll do the easy things first, and then assume lots of them before we look at the algorithm. Style Usually C#ers ...
VisualMelon's user avatar
  • 7,591
8 votes

Compute shortest path in undirected graph

Intro code: There's a lot of "instant fail"s here: Include only the headers you need! Debugging macros are probably not acceptable for something like this. We can step through in a ...
user673679's user avatar
  • 12.2k
8 votes

Faux Random Maze Generator

get_direction works too hard. Expanding on Fe2O3 suggestion, notice that dx and dy are ...
vnp's user avatar
  • 58.7k
8 votes
Accepted

Shortest unrestricted path to touch every square in an n by n grid

Time complexity You have \$O(n^2)\$ start points. Each of those run a DFS. Assuming, as a lower bound, that the DFS explores every possible edge, then that's \$O(n^2)\$ steps per DFS. The actual ...
G. Sliepen's user avatar
  • 69.3k
7 votes
Accepted

Fastest path on a snakes and ladders board

Don't use mutable default arguments. If you need to default to a list then default to None and then change to an empty list. Take the following example code: <...
Peilonrayz's user avatar
  • 44.6k
7 votes

Implementation of Dijkstra's algorithm in Python

[x for x in range(1, 1001)] can be written as just list(range(1, 1001)). It would be good to give that ...
Carcigenicate's user avatar
7 votes
Accepted

Optimizing Python BFS Code

current = queue.pop() What this actually does, which perhaps you did not notice, is remove the last element of the list. So the queue is really a stack, and ...
user555045's user avatar
  • 12.4k
7 votes

Bellman-Ford optimisation in C

A few pieces of advice you can consider: As far as I'm aware, documentation comments are conventionally immediately before the declaration, not between the signature and the body of the ...
Solomon Ucko's user avatar
  • 1,576
7 votes

Faux Random Maze Generator

This looks good overall. I'll try not to repeat other answers, sorry if something is still duplicated. I've got a couple of "major" notes that indeed raised my eyebrows, and then several ...
STerliakov's user avatar
  • 2,072
6 votes

Find the correct path through a 5 x 5 grid (coderbyte 'Correct path')

calcpath should be calc_path as per PEP8. This seems like it's a name decided on by the challenge, but I thought I'd mention it. ...
Carcigenicate's user avatar
6 votes
Accepted

Speeding up Dijkstra's algorithm

PEP-8 Violations Variables (unseenNodes, currentNode) should be snake_case, not ...
AJNeufeld's user avatar
  • 35.3k
6 votes
Accepted

A* (shortest path) with the ability to remove up to one wall

The high level approach What would be a good way of implementing the wall logic to be within the A* algorithm? I've tried to simply add a canRemove boolean to the Cell object (which is holding the ...
user555045's user avatar
  • 12.4k
6 votes
Accepted

Multithreading a shortest path algorithm

Avoid redefining integer types I see types like sint and uint, I think somewhere you have lines like: ...
G. Sliepen's user avatar
  • 69.3k
6 votes

Computing most probable (reliable) path in a probabilistic graph (take II)

Two stylistic things jump out at me. You use StringBuilder in the below, but elsewhere you use String.format. ...
Chris's user avatar
  • 4,614
5 votes
Accepted

Google FooBar "Prepare The Bunnies Escape"

SPOILER ALERT This puzzle is a very slight modification of the well-known fuzzy string matching problem, which can be solved efficiently using (what else?) dynamic programming. Imagine you're a bunny ...
Quuxplusone's user avatar
  • 19.7k
5 votes

Fastest path on a snakes and ladders board

continue # Forbid a dice-roll that lands on a snake This may prevent finding the shortest path - it's possible to imagine a board with two long ladders, ...
Toby Speight's user avatar
  • 88.3k
5 votes

Implementation of A* algorithm in C++

Just off the cuff, before I fully code review this, I would tell you: 1) There are not enough comments. You add comments like this: ...
Gabriel Rohweder's user avatar
5 votes
Accepted

C#: A* pathfinding - performance and simplicity

Boxing from value PathNode to reference IPathNode causes another half of allocations. But making ...
user555045's user avatar
  • 12.4k
5 votes
Accepted

Python: Astar algorithm implementation

self.start, self.grid, self.height, self.width = start, grid, height, width I would not put these all on the same line like that. I think it would be much easier ...
Carcigenicate's user avatar
5 votes

Compute shortest path in undirected graph

In addition to user673679 and Toby Speight's answers, here are a few more issues: Use a consistent code style Sometimes I see spaces around commas, sometimes not, the body of ...
G. Sliepen's user avatar
  • 69.3k
5 votes
Accepted

Searching for a performance bug in a C++20 pathfinding algorithm (NBA*)

Avoid manual new and delete I see a lot of new and delete...
G. Sliepen's user avatar
  • 69.3k

Only top scored, non community-wiki answers of a minimum length are eligible