Compare commits

...

5 Commits

  1. 1
      .gitignore
  2. 8
      src/Day.h
  3. 19
      src/days/01/Day01.cpp
  4. 2
      src/days/01/Day01.h
  5. 2
      src/main.cpp
  6. 5
      src/util.h

1
.gitignore vendored

@ -3,3 +3,4 @@ session
/input/
/xtensor/
/xtl/
.idea

@ -24,16 +24,16 @@ public:
std::cout << "Task 1" << std::endl;
Result result1 = Task1();
auto stop1 = high_resolution_clock::now();
auto dur1 = duration_cast<milliseconds>(stop1 - start);
auto dur1 = duration_cast<microseconds>(stop1 - start);
std::cout << "Result: " << result1 << std::endl;
std::cout << "Duration: " << dur1.count() << "ms" << std::endl;
std::cout << "Duration: " << double(dur1.count()) / 1000. << "ms" << std::endl;
std::cout << "Task 2" << std::endl;
Result result2 = Task2();
auto stop2 = high_resolution_clock::now();
auto dur2 = duration_cast<milliseconds>(stop2 - stop1);
auto dur2 = duration_cast<microseconds>(stop2 - stop1);
std::cout << "Result: " << result2 << std::endl;
std::cout << "Duration: " << dur2.count() << "ms" << std::endl << std::endl;
std::cout << "Duration: " << double(dur2.count()) / 1000. << "ms" << std::endl << std::endl;
return 0;
}

@ -1,9 +1,24 @@
#include "Day01.h"
Result Day01::Task1() {
return Day::Task1();
subSums.push_back(0);
for (const std::string& line : input){
if (line.empty())
subSums.push_back(0);
else
subSums[subSums.size() - 1] += stoi(line);
}
return to_string(*std::max_element(subSums.begin(), subSums.end()));
}
Result Day01::Task2() {
return Day::Task2();
std::sort(subSums.begin(), subSums.end());
int sum = 0;
for (int i = 0; i < 3; i++){
sum += subSums.back();
subSums.pop_back();
}
return to_string(sum);
}

@ -7,4 +7,6 @@ protected:
Result Task1() override;
Result Task2() override;
std::vector<int> subSums;
};

@ -15,7 +15,7 @@ Input getInput(int day, std::string key, bool useTestInput) {
if (key.empty())
return input;
std::string dayStr = std::to_string(day);
std::string url = "https://adventofcode.com/2021/day/" + dayStr + "/input";
std::string url = "https://adventofcode.com/2022/day/" + dayStr + "/input";
std::cout << "Input does not exist. Fetching from " + url << std::endl;
std::ofstream file(localFilePath);
file << cpr::Get(cpr::Url{url}, cpr::Cookies{{"session", key}}).text;

@ -4,4 +4,7 @@
#include <numeric>
#include <string>
#include <tuple>
#include <iostream>
#include <iostream>
using std::stoi, std::to_string;
using std::cout, std::endl;
Loading…
Cancel
Save