Added the last functionality to calculate the answer

This commit is contained in:
Stedd 2024-12-01 13:38:57 +01:00
parent da436272dc
commit 370370585e
2 changed files with 13 additions and 20 deletions

View File

@ -77,6 +77,7 @@ void day01::Run()
{
std::list<int> col1;
std::list<int> col2;
int sum = 0;
// std::ifstream input("input/day01.txt");
std::ifstream input("input/day01short.txt");
@ -96,7 +97,16 @@ void day01::Run()
while (std::getline(input, line))
{
auto delimiterPos = line.find(delimiter);
std::string firstNumber = line.substr(0, delimiterPos);
std::string secondNumber = line.substr(delimiterPos + delimiterLength, line.length());
col1.emplace_back(std::stoi(line.substr(0, delimiterPos)));
col2.emplace_back(std::stoi(line.substr(delimiterPos + delimiterLength, line.length())));
}
col1.sort();
col2.sort();
for (int i = 0; i < col1.size(); ++i)
{
sum+= col1[i]-col2[i];
}
}

View File

@ -1,20 +1,3 @@
66845 37619
94793 99076
76946 36179
27374 48777
47847 92154
83270 97857
19354 94331
69716 58559
16902 36957
51817 88003
40758 64262
39074 90635
34632 79874
64980 96787
96137 94559
55489 98589
95130 76776
50275 50416
46438 49722
34182 49722
76946 36179