Advent of Code 2025, done in C++

day[04]: final touches to Matrix API

bpavuk.neocities.org 3cb7f065 2c12894f

verified
Changed files
+8 -10
src
+8 -10
src/04/solution.cxx
··· 21 21 22 22 unsigned long height() { return data.size(); } 23 23 24 - std::string operator[](unsigned long idx) { return data[idx]; } 24 + std::string &operator[](unsigned long idx) { return data[idx]; } 25 + 26 + const std::string &operator[](unsigned long idx) const { return data[idx]; } 25 27 26 28 std::string get_surrounding(unsigned long row, unsigned long col) { 27 29 std::string sur = ""; ··· 29 31 unsigned long wid = width(); 30 32 auto hi = height(); 31 33 32 - if (row > 0 && col - 1 >= 0) { 34 + if (row > 0 && col > 0) { 33 35 sur += data[row - 1][col - 1]; 34 36 } 35 37 if (row > 0) { ··· 57 59 return sur; 58 60 } 59 61 60 - void set(unsigned long row, unsigned long col, char ch) { 61 - data[row][col] = ch; 62 - } 63 - 64 62 private: 65 63 std::vector<std::string> data{}; 66 64 }; ··· 88 86 if (count >= 4) { 89 87 continue; 90 88 } 91 - auto roll = Roll { 92 - .row = row, 93 - .col = col, 89 + auto roll = Roll{ 90 + .row = row, 91 + .col = col, 94 92 }; 95 93 rolls.push_back(roll); 96 94 } ··· 101 99 102 100 int remove_rolls(Matrix &data, std::span<Roll> removables) { 103 101 for (auto roll : removables) { 104 - data.set(roll.row, roll.col, '.'); 102 + data[roll.row][roll.col] = '.'; 105 103 } 106 104 107 105 return removables.size();