-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04-Printing-Department.cpp
More file actions
49 lines (38 loc) · 1.57 KB
/
04-Printing-Department.cpp
File metadata and controls
49 lines (38 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (C) 2025 Joe Baker (JoeBlakeB)
// Advent of Code 2025 - Day 4: Printing Department
// Usage:
// scripts/cppRun.sh 2025/04-Printing-Department.cpp < 2025/inputs/04.txt
#include <iostream>
#include <string>
#include <vector>
#include "../Utils/Grid.cpp"
using namespace std;
int forkliftRemoveRollsOfPaper(CharGrid& printingDepartment) {
int accessibleByForklift = 0;
CharGrid printingDepartmentAfter = printingDepartment;
printingDepartment.forEach([&printingDepartment, &printingDepartmentAfter, &accessibleByForklift](Coordinate position) {
if (printingDepartment[position] != '@') {
return;
}
vector<char> neighbors = printingDepartment.neighborValues(position, true);
int adjacentPaperRolls = std::count_if(neighbors.begin(), neighbors.end(), [](char x) { return x == '@'; });
if (adjacentPaperRolls < 4) {
printingDepartmentAfter[position] = ' ';
accessibleByForklift++;
}
});
printingDepartment = printingDepartmentAfter;
return accessibleByForklift;
}
int main() {
CharGrid printingDepartment = {cin};
int accessibleByForklift = forkliftRemoveRollsOfPaper(printingDepartment);
cout << "accessible rolls of paper: " << accessibleByForklift << endl;
int totalRemoved = accessibleByForklift;
do {
accessibleByForklift = forkliftRemoveRollsOfPaper(printingDepartment);
totalRemoved += accessibleByForklift;
} while (accessibleByForklift != 0);
cout << "total that can be removed: " << totalRemoved << endl;
return 0;
}