diff options
author | jacopograndi <jacopo.grandi@outlook.it> | 2022-01-06 18:44:53 +0100 |
---|---|---|
committer | jacopograndi <jacopo.grandi@outlook.it> | 2022-01-06 18:44:53 +0100 |
commit | 6f96b2014b053a2e6e5a37464ca6fc578607fda7 (patch) | |
tree | cdb4686352eeadb2225b984ab56819c7de285af4 /day01/day01.cpp | |
parent | 9f7b0cd76272068588d0a7220408f91390c5b583 (diff) |
rm
Diffstat (limited to 'day01/day01.cpp')
-rw-r--r-- | day01/day01.cpp | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/day01/day01.cpp b/day01/day01.cpp deleted file mode 100644 index 113f86d..0000000 --- a/day01/day01.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include <iostream> -#include <string> -#include <vector> -#include <algorithm> - -std::string read (char* name) { - FILE *f = fopen(name, "r"); - char c = fgetc(f); std::string txt; - while (c != EOF) { txt += c; c = fgetc(f); } - fclose(f); - return txt; -} - -std::vector<std::string> split (std::vector<std::string> vec, std::string name) { - auto token = name.find("\n"); - if (token != std::string::npos) { - vec.push_back(name.substr(0, token)); - return split(vec, name.substr(token+1)); - } else if (name.size() > 1) { - vec.push_back(name); - } - return vec; -} - -int main (int argc, char* argv[]) { - if (argc < 2 && argc > 3) return 1; - std::string txt = read(argv[1]); - - std::vector<std::string> vec; - vec = split(vec, txt); - std::vector<int> depths; - for (auto v : vec) { - depths.push_back(std::stoi(v)); - } - - int window = 1; - if (argc == 3) { window = atoi(argv[2]); } - - int inc = 0; - for (std::size_t i=0; i<depths.size(); i++) { - if (i >= window) { - int sum0 = 0, sum1 = 0; - for (int j=0; j<window; j++) sum0 += depths[i-j-1]; - for (int j=0; j<window; j++) sum1 += depths[i-j]; - if (sum1 > sum0) inc ++; - } - } - - std::cout << "The number of depth increases is " << inc << std::endl; - - return 0; -} |