diff --git a/2024/7/Makefile b/2024/7/Makefile new file mode 100644 index 0000000..638e325 --- /dev/null +++ b/2024/7/Makefile @@ -0,0 +1,2 @@ +a.out: main.cpp + clang++ -std=c++2b -g -O0 main.cpp diff --git a/2024/7/data_test.txt b/2024/7/data_test.txt new file mode 100644 index 0000000..fc6e099 --- /dev/null +++ b/2024/7/data_test.txt @@ -0,0 +1,9 @@ +190: 10 19 +3267: 81 40 27 +83: 17 5 +156: 15 6 +7290: 6 8 6 15 +161011: 16 10 13 +192: 17 8 14 +21037: 9 7 18 13 +292: 11 6 16 20 diff --git a/2024/7/main.cpp b/2024/7/main.cpp new file mode 100644 index 0000000..ff0f6bf --- /dev/null +++ b/2024/7/main.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include + +int main() +{ + std::ifstream ifs("data_test.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> cals; + + for(std::string line; std::getline(ifs, line); ) + { + if(line == "") + continue; + + cals.push_back({}); + std::istringstream input(line); + // for each value in the line: + std::vector nums; + for(std::string value; std::getline(input, value, ' '); ) + cals.back().push_back(std::atoi(value.c_str())); + } + + for(auto cal : cals) + { + for(auto num : cal) + { + std::cout << num << " "; + } + std::cout << std::endl; + } + + + std::cout << " Total: " << total << std::endl; + std::cout << "PT2 Total: " << total_pt2 << std::endl; + + return 0; +}