Cleanup 2016 day 22 puzzles

This commit is contained in:
2021-12-09 15:05:31 +00:00
parent 1da63f3e9c
commit 26ef423b62
2 changed files with 69 additions and 0 deletions

62
2016/puzzle-22-01.cc Normal file
View File

@@ -0,0 +1,62 @@
#include <iostream>
#include <regex>
#include <string>
#include <vector>
struct Node
{
unsigned long x_;
unsigned long y_;
unsigned long size_;
unsigned long used_;
unsigned long avail_;
unsigned long percent_;
};
using NodeVector = std::vector<Node>;
auto main() -> int
{
static std::regex header_re{R"(^Filesystem\s+Size\s+Used\s+Avail\s+Use%$)"};
static std::regex header2_re{"^root@"};
static std::regex info_re{
R"(^/dev/grid/node-x(\d+)-y(\d+)\s+(\d+)T\s+(\d+)T\s+(\d+)T\s+(\d+)%$)"};
std::string line;
NodeVector nodes;
std::smatch m;
while (std::getline(std::cin, line)) {
if (std::regex_search(line, m, header_re)) {
continue;
}
if (std::regex_search(line, m, header2_re)) {
continue;
}
if (std::regex_search(line, m, info_re)) {
nodes.push_back({std::stoul(m.str(1)), std::stoul(m.str(2)), std::stoul(m.str(3)),
std::stoul(m.str(4)), std::stoul(m.str(5)), std::stoul(m.str(6))});
}
else {
std::cerr << "Unable to interpret: " << line << '\n';
return 1;
}
}
unsigned viable{0};
for (auto it1{nodes.begin()}; it1 != nodes.end(); ++it1) {
if (it1->used_ == 0) {
continue;
}
for (auto it2{nodes.begin()}; it2 != nodes.end(); ++it2) {
if (it2 == it1) {
continue;
}
if (it1->used_ <= it2->avail_) {
++viable;
}
}
}
std::cout << "Viable " << viable << '\n';
return 0;
}

7
2016/puzzle-22-02.cc Normal file
View File

@@ -0,0 +1,7 @@
#include <iostream>
auto main() -> int
{
std::cout << "Worked it out by hand: 233\n";
return 0;
}