From 370370585edbbb4e1d3c4364e9bb8a3283f757e2 Mon Sep 17 00:00:00 2001 From: Stedd Date: Sun, 1 Dec 2024 13:38:57 +0100 Subject: [PATCH] Added the last functionality to calculate the answer --- days/day01.cpp | 14 ++++++++++++-- input/day01short.txt | 19 +------------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/days/day01.cpp b/days/day01.cpp index 293c505..00f759f 100644 --- a/days/day01.cpp +++ b/days/day01.cpp @@ -77,6 +77,7 @@ void day01::Run() { std::list col1; std::list 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]; } } diff --git a/input/day01short.txt b/input/day01short.txt index e01c1b1..6c333c5 100644 --- a/input/day01short.txt +++ b/input/day01short.txt @@ -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 \ No newline at end of file +76946 36179 \ No newline at end of file