Pre-compute initial explode actions - #105
Open
ebblake wants to merge 1 commit into
Open
Conversation
During part two, we are computing a pairing between every two lines. Any line that had one or more depth 4 number pairs will cause the same set of explode actions to be taken for each of the other 99 lines it is paired with, before we get into the main effort of add() in processing split actions. Rather than repeat early work that will produce the same answer, we can instead pre-compute these initial explode calls during parse time. On my input, adding a simple counter shows that this reduces the number of calls to explode() from 180k down to 131k. parse() and part1() runtimes are about the same, while part2() speeds up from 600us to 560us.
Contributor
Author
Contributor
Author
|
It would also be an interesting experiment (one I still need to run) to see if there is any reliable relation between magnitude(reduce([left,0])) and the eventual magnitude(reduce([left,right])) winner. For example, if the winning magnitude always depends on one of the top-ten magnitude values out of the 100 inputs being on the left, we could avoid a full 100*99 add() calls in part 2 and instead focus on the ones most likely to produce a large value. But it is complicated by the fact that split() means the mapping is not straightforward: |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
During part two, we are computing a pairing between every two lines. Any line that had one or more depth 4 number pairs will cause the same set of explode actions to be taken for each of the other 99 lines it is paired with, before we get into the main effort of add() in processing split actions. Rather than repeat early work that will produce the same answer, we can instead pre-compute these initial explode calls during parse time.
On my input, adding a simple counter shows that this reduces the number of calls to explode() from 180k down to 131k. parse() and part1() runtimes are about the same, while part2() speeds up from 600us to 560us.
Type of change
Checklist
using the same naming conventions. Code should be portable, avoiding any
architecture-specific intrinsics.
cargo testcargo fmt -- `find . -name "*.rs"`cargo clippy --all-targets --all-featuresFormatting and linting also can be executed by running
just(if installed) on the command line at the project root.