Added some missing old files and new day2 of 2024.
This commit is contained in:
@@ -53,3 +53,4 @@ Monkey 7:
|
||||
Test: divisible by 11
|
||||
If true: throw to monkey 0
|
||||
If false: throw to monkey 2
|
||||
|
||||
|
@@ -4,6 +4,40 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum Operation {
|
||||
ADD,
|
||||
MULTIPLY,
|
||||
};
|
||||
|
||||
class Monkey {
|
||||
public:
|
||||
Monkey(const std::vector<int> &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<int> items;
|
||||
|
||||
Operation operation_type;
|
||||
int operation_amount;
|
||||
|
||||
int division_by;
|
||||
|
||||
int true_monkey;
|
||||
int false_monkey;
|
||||
};
|
||||
|
||||
std::vector<int> ParseItems(const std::string &line);
|
||||
std::pair<Operation, int> 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");
|
||||
@@ -16,14 +50,65 @@ int main()
|
||||
unsigned long total = 0;
|
||||
unsigned long total_pt2 = 0;
|
||||
|
||||
std::vector<Monkey> monkeys;
|
||||
int line_num = 0;
|
||||
std::vector<std::string> 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<int> ParseItems(const std::string &line)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
std::pair<Operation, int> 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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user