From da436272dc58761077b6970114734ffd32a4c602 Mon Sep 17 00:00:00 2001 From: Stedd Date: Sun, 1 Dec 2024 13:19:04 +0100 Subject: [PATCH] able to read the input and split input into two strings --- days/day01.cpp | 29 ++++++++++++++++++++++++++++- input/day01.txt | 2 +- input/day01short.txt | 20 ++++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 input/day01short.txt diff --git a/days/day01.cpp b/days/day01.cpp index bc27031..293c505 100644 --- a/days/day01.cpp +++ b/days/day01.cpp @@ -4,8 +4,12 @@ #include "day01.h" +#include #include +#include #include +#include +#include /* --- Day 1: Historian Hysteria --- @@ -71,5 +75,28 @@ Your actual left and right lists contain many location IDs. What is the total di void day01::Run() { - std::cout << "Day 01" << std::endl; + std::list col1; + std::list col2; + + // std::ifstream input("input/day01.txt"); + std::ifstream input("input/day01short.txt"); + + if (!input) + { + std::cerr << "Failed to open input file." << std::endl; + std::cout << "Current path is " << std::filesystem::current_path() << '\n'; + + return; + } + + std::string delimiter = " "; + auto delimiterLength = delimiter.length(); + + std::string line; + 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()); + } } diff --git a/input/day01.txt b/input/day01.txt index 40b3746..35cf541 100644 --- a/input/day01.txt +++ b/input/day01.txt @@ -997,4 +997,4 @@ 30895 46438 69966 25582 31783 85509 -97288 51968 +97288 51968 \ No newline at end of file diff --git a/input/day01short.txt b/input/day01short.txt new file mode 100644 index 0000000..e01c1b1 --- /dev/null +++ b/input/day01short.txt @@ -0,0 +1,20 @@ +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