-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
388 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "day11_cosmic_expansion" | ||
version = "0.1.0" | ||
edition = "2021" | ||
rust-version.workspace = true | ||
|
||
[dependencies] | ||
log.workspace = true | ||
env_logger.workspace = true | ||
ndarray.workspace = true | ||
itertools.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
My first thought reading this was [Floyd-Warshall](https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm). | ||
But since this is a discrete matrix then the distances between the galaxies can | ||
be computed using a simple [Taxicab/Manhattan distance](https://en.wikipedia.org/wiki/Taxicab_geometry). | ||
Now, the crucial piece of information that makes this work is that "the | ||
shortest path between two galaxies is allowed to pass through another galaxy". | ||
Without this, the taxicab distance _does not_ work. I did not read that part | ||
initially so I had dismissed this solution, instead looking into how to | ||
implement [A\*](https://en.wikipedia.org/wiki/A*_search_algorithm). | ||
|
||
I remember seeing on reddit the expression "Advent of reading comprehension" | ||
and this is the perfect example of that. The constraint did eventually register | ||
with me so I went back to taxicab but I had spent quite a bit of time to reach | ||
that point. | ||
|
||
--- | ||
|
||
Regarding the implementation itself, there's nothing special, this was just | ||
another one of those mathy problems and I lucked out on part 2 being easy | ||
purely because I didn't choose to go for a graph implementation in part 1. Meh. |
Oops, something went wrong.