Skip to content

day 8#7

Merged
efvincent merged 3 commits into
mainfrom
y2015d08
Jul 20, 2026
Merged

day 8#7
efvincent merged 3 commits into
mainfrom
y2015d08

Conversation

@efvincent

Copy link
Copy Markdown
Owner

Summary

  • Adds the 2015 day 8 puzzle implementation.
  • Wires day 8 into the 2015 dispatcher.

Validation

  • make debug

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 y2015d08 module 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);
});
@efvincent
efvincent merged commit 98c85cb into main Jul 20, 2026
1 check passed
@efvincent
efvincent deleted the y2015d08 branch July 20, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants