Complete Day 16 Packet Decoder implementation for both parts #13
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.
The Day 16 Packet Decoder implementation was incomplete and only outputted "2021" without solving either part of the challenge. This PR completes the implementation to fully decode BITS (Buoyancy Interchange Transmission System) packets and solve both parts.
Key Changes
Fixed literal value parsing bug: The original code incorrectly initialized the pointer position and had flawed parsing logic for literal value packets.
Implemented complete operator packet parsing: Added support for both length type ID modes:
Added recursive packet structure handling: The decoder now properly handles nested packets of arbitrary depth, maintaining correct position tracking throughout the parsing process.
Implemented Part 1 solution: Calculates the sum of all version numbers across the entire packet hierarchy.
Implemented Part 2 solution: Evaluates packet expressions according to their type IDs:
Example Usage
The implementation now correctly handles all test cases from the problem description, including complex nested expressions with multiple operation types.
Fixes #7.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.