Signed-off-by: Jack Bond-Preston <jackbondpreston@outlook.com>
This commit is contained in:
Jack Bond-Preston 2021-12-01 19:01:35 +00:00
commit f7a3960814
3 changed files with 83 additions and 0 deletions

35
.gitignore vendored Normal file
View File

@ -0,0 +1,35 @@
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
.vscode
input.txt

19
1/1a.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <fstream>
#include <climits>
#include <iostream>
int main() {
std::ifstream infile("input.txt");
unsigned int curr, prev = UINT_MAX;
unsigned int increases = 0;
while (infile >> curr) {
if (curr > prev) ++increases;
prev = curr;
}
std::cout << increases << std::endl;
return 0;
}

29
1/1b.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <fstream>
#include <climits>
#include <iostream>
#include <vector>
int main() {
std::ifstream infile("input.txt");
std::vector<int> window { 0, 0, 0 };
int curr = 0;
unsigned int increases = 0;
infile >> window[0];
infile >> window[1];
infile >> window[2];
while (infile >> curr) {
int prev_sum = window[0] + window[1] + window[2];
int new_sum = window[1] + window[2] + curr;
if (new_sum > prev_sum) ++increases;
window = { window[1], window[2], curr };
}
std::cout << increases << std::endl;
return 0;
}