I'm not sure why I'm awake, so I'll do this tomorrow.

This commit is contained in:
David Vereb 2024-12-07 01:57:47 -05:00
parent 156f1e7dac
commit ddcf072281
3 changed files with 60 additions and 0 deletions

2
2024/7/Makefile Normal file
View File

@ -0,0 +1,2 @@
a.out: main.cpp
clang++ -std=c++2b -g -O0 main.cpp

9
2024/7/data_test.txt Normal file
View File

@ -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

49
2024/7/main.cpp Normal file
View File

@ -0,0 +1,49 @@
#include <fstream>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>
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<std::vector<long>> 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<long> 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;
}