#include #include #include #include #include enum Operation { ADD, MULTIPLY, }; class Monkey { public: Monkey(const std::vector &starting_items, Operation operation_type, int operation_amount, int division_by, int true_monkey, int false_monkey) : items(starting_items), operation_type(operation_type), operation_amount(operation_amount), division_by(division_by), true_monkey(true_monkey), false_monkey(false_monkey) { } friend std::ostream& operator<<(std::ostream &out, const Monkey &monkey); private: std::vector items; Operation operation_type; int operation_amount; int division_by; int true_monkey; int false_monkey; }; std::vector ParseItems(const std::string &line); std::pair ParseOperation(const std::string &line); int ParseDivisibleBy(const std::string &line); int ParseTrue(const std::string &line); int ParseFalse(const std::string &line); int main() { std::ifstream ifs("data.txt"); if(!ifs.is_open()) { std::cerr << "Missing data.txt." << std::endl; return -1; } unsigned long total = 0; unsigned long total_pt2 = 0; std::vector monkeys; int line_num = 0; std::vector buf; for(std::string line; std::getline(ifs, line); ) { if(line == "") { if(buf.size() == 5) { auto op = ParseOperation(buf[2]); monkeys.push_back(Monkey(//std::atoi(buf[0].substr(7, buf[0].size() - 7).c_str()), ParseItems(buf[1]), op.first, op.second, ParseDivisibleBy(buf[3]), ParseTrue(buf[4]), ParseFalse(buf[5]))); buf.clear(); } continue; } else if(line.starts_with(" ")) buf.push_back(line); } for(const auto &monkey : monkeys) std::cout << monkey << std::endl; std::cout << " Total: " << total << std::endl; std::cout << "PT2 Total: " << total_pt2 << std::endl; return 0; } std::ostream& operator<<(std::ostream &out, const Monkey &monkey) { out << " Starting items: "; for(auto item : monkey.items) out << item << ", "; return out; } std::vector ParseItems(const std::string &line) { return {}; } std::pair ParseOperation(const std::string &line) { return { Operation::ADD, 0 }; } int ParseDivisibleBy(const std::string &line) { return 1; } int ParseTrue(const std::string &line) { return 1; } int ParseFalse(const std::string &line) { return 1; }