Skip to content

Commit 06ad62e

Browse files
authored
Document choice for using slower algorithm (#41)
#32 proposed speeding up 2021 part 2 to use a linear algorithm; but the pull request was closed unapplied because the savings were in the noise compared to the already time-consuming algorithm required in parse to even get to the point where distances can be computed. Still, it is worth documenting the approach as an aid to anyone else using this repository for inspiration.
1 parent 91f69c9 commit 06ad62e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/year2021/day19.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ pub fn part1(input: &[Located]) -> usize {
213213
pub fn part2(input: &[Located]) -> i32 {
214214
let mut result = 0;
215215

216+
// This solution uses the usual quadratic pairing of every point. This is okay because
217+
// the set is not terribly large, and the runtime here is dwarfed by the earlier runtime
218+
// taken to get the coordinates in place. However, a linear solution is also possible:
219+
// https://www.reddit.com/r/adventofcode/comments/rygnl8/2021_day_19_part_2pseudocode_speeding_up/
216220
for first in input {
217221
for second in input {
218222
result = result.max(first.translation.manhattan(&second.translation));

0 commit comments

Comments
 (0)