Separate out Dijkstra implementation

This separates the Dijkstra implementation into its own generic function.

Whilst doing this we can simplify the code and also save yet more memory!

Still don't get correct results for part 2.
This commit is contained in:
2022-01-12 11:31:09 +00:00
parent a1a7d11583
commit 3ba00ad3eb
3 changed files with 45 additions and 11 deletions

View File

@@ -169,6 +169,18 @@ private:
std::array<Type, 15> State::finished_ = {'.', '.', '.', '.', '.', '.', '.', 'A',
'B', 'C', 'D', 'A', 'B', 'C', 'D'};
std::ostream& operator<<(std::ostream& os, State const& s)
{
os << "#############\n"
<< '#' << s.node(0) << s.node(1) << '.' << s.node(2) << '.' << s.node(3) << '.' << s.node(4)
<< '.' << s.node(5) << s.node(6) << "#\n"
<< "###" << s.node(7) << '#' << s.node(8) << '#' << s.node(9) << '#' << s.node(10) << "###\n"
<< " #" << s.node(11) << '#' << s.node(12) << '#' << s.node(13) << '#' << s.node(14) << "#\n"
<< " #########\n";
return os;
}
struct StateTranstitionManager
{
bool is_finished(State const& state) { return state.finished(); }