Conversation
There was a problem hiding this comment.
Pull request overview
Adds Advent of Code 2015 Day 8 (“Matchsticks”) to the C++ puzzles codebase and wires it into the 2015 puzzle dispatcher so it can be executed like the other implemented days.
Changes:
- Added
y2015d08module implementing part 1 and part 2 character-counting logic. - Wired Day 8 into the 2015 switch/dispatcher in
puzzles.cppm. - Added the Day 8 input data file and updated the Day 0 placeholder to exercise scratch allocation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| src/puzzles/puzzles.cppm | Imports y2015d08 and adds dispatcher case for day 8 parts 1/2. |
| src/puzzles/2015/y2015d08.cppm | Implements Day 8 solution logic (code-vs-memory and re-encoding length diffs). |
| src/puzzles/2015/y2015d00.cppm | Updates placeholder day to allocate from a scoped scratch arena (avoids unused parameter). |
| data/2015/day08.txt | Adds the 2015 Day 8 input dataset. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+21
to
+24
| struct LineStats { | ||
| u16 code; | ||
| u16 chars; | ||
| }; |
Comment on lines
+26
to
+30
| LineStats count_chars(Str8& line) { | ||
| LineStats stats = {2, 0}; | ||
| for(u64 i = 1; i < line.len - 1;) { | ||
| // start at the second char, and loop to penultimate char, knowing | ||
| // that each line starts and ends with a double quote |
Comment on lines
+69
to
+73
| while (iter_next(cursor, current, '\n')) { | ||
| auto current_stats = count_chars(current); | ||
| total_chars += current_stats.chars; | ||
| total_code += current_stats.code; | ||
| } |
Comment on lines
+54
to
+59
| u16 reencoded_len(Str8 s) { | ||
| BASE_ASSERT(s.str != nullptr && s.len > 0); | ||
| u16 count = 2; | ||
| for (u64 i = 0; i < s.len; i++) { | ||
| count += s.str[i] == '"' || s.str[i] == '\\' ? 2 : 1; | ||
| } |
Comment on lines
+84
to
+88
| while (iter_next(cursor, current, '\n')) { | ||
| auto reencoded = reencoded_len(current); | ||
| total_old += current.len; | ||
| total_new += reencoded; | ||
| } |
Comment on lines
+21
to
+23
| arena.scoped_scratch([&](Arena& arena) { | ||
| arena.alloc_array<u64>(20); | ||
| }); |
Comment on lines
+29
to
+31
| arena.scoped_scratch([&](Arena& arena) { | ||
| arena.alloc_array<u64>(20); | ||
| }); |
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.
Summary
Validation