diff options
Diffstat (limited to '2025')
| -rw-r--r-- | 2025/src/day09.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/2025/src/day09.cpp b/2025/src/day09.cpp new file mode 100644 index 0000000..f46112a --- /dev/null +++ b/2025/src/day09.cpp | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | #include <filesystem> | ||
| 2 | #include <fstream> | ||
| 3 | #include <iostream> | ||
| 4 | #include <tuple> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | using namespace std; | ||
| 8 | |||
| 9 | namespace { | ||
| 10 | |||
| 11 | using Pos = tuple<long, long>; | ||
| 12 | |||
| 13 | vector<Pos> | ||
| 14 | read_file(const filesystem::path& filename) | ||
| 15 | { | ||
| 16 | ifstream file{ filename }; | ||
| 17 | |||
| 18 | vector<Pos> data; | ||
| 19 | |||
| 20 | long x{}; | ||
| 21 | long y{}; | ||
| 22 | char skip{}; | ||
| 23 | |||
| 24 | while ( file >> x >> skip >> y ) { | ||
| 25 | data.emplace_back(x, y); | ||
| 26 | } | ||
| 27 | return data; | ||
| 28 | } | ||
| 29 | |||
| 30 | void | ||
| 31 | part1(const vector<Pos>& data) | ||
| 32 | { | ||
| 33 | auto area = numeric_limits<long>::min(); | ||
| 34 | |||
| 35 | for ( size_t i = 0; i != data.size(); ++i ) { | ||
| 36 | for ( size_t j = i + 1; j != data.size(); ++j ) { | ||
| 37 | const auto [x1, y1] = data[i]; | ||
| 38 | const auto [x2, y2] = data[j]; | ||
| 39 | |||
| 40 | const auto width = abs(x1 - x2) + 1; | ||
| 41 | const auto height = abs(y1 - y2) + 1; | ||
| 42 | |||
| 43 | area = max(area, width * height); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | cout << "Part 1: " << area << '\n'; | ||
| 47 | } | ||
| 48 | |||
| 49 | } // namespace | ||
| 50 | |||
| 51 | int | ||
| 52 | main() | ||
| 53 | { | ||
| 54 | auto data = read_file("data/day09.txt"); | ||
| 55 | part1(data); | ||
| 56 | } | ||
