diff --git a/day1/input.txt b/day1/data/input.txt similarity index 100% rename from day1/input.txt rename to day1/data/input.txt diff --git a/day1/data/testInput.txt b/day1/data/testInput.txt new file mode 100644 index 0000000..270a0a8 --- /dev/null +++ b/day1/data/testInput.txt @@ -0,0 +1,10 @@ +103 +106 +107 +110 +121 +132 +147 +148 +144 +141 diff --git a/day1/day1Part1 b/day1/day1Part1 new file mode 100755 index 0000000..359c320 Binary files /dev/null and b/day1/day1Part1 differ diff --git a/day1/day1Part1.cpp b/day1/day1Part1.cpp new file mode 100644 index 0000000..6f6afa4 --- /dev/null +++ b/day1/day1Part1.cpp @@ -0,0 +1,24 @@ +#include +#include +using namespace std; + +int main(void) +{ + int lastValue = 0; + int currentValue = 0; + int decreaseCount = 0; + cout << "test\n"; + ifstream readFile ("data/input.txt", ios::in); + + while(readFile >> currentValue) + { + if (lastValue != 0) + { + if (lastValue < currentValue) decreaseCount++; + cout << decreaseCount << "\n"; + } + lastValue = currentValue; + } + cout << decreaseCount; + return 0; +} diff --git a/day1/day1Part2 b/day1/day1Part2 new file mode 100755 index 0000000..b9cf014 Binary files /dev/null and b/day1/day1Part2 differ diff --git a/day1/day1Part2.cpp b/day1/day1Part2.cpp new file mode 100644 index 0000000..3fe2c93 --- /dev/null +++ b/day1/day1Part2.cpp @@ -0,0 +1,34 @@ +#include +#include +using namespace std; + +int main(void) +{ + int lastValue = 0; + int middleValue = 0; + int currentValue = 0; + int sum1 = 0; + int sum2 = 0; + int decreaseCount = -1; + ifstream readFile ("data/input.txt", ios::in); + + while(readFile >> currentValue) + { + sum1 = lastValue + middleValue + currentValue; + if (lastValue != 0) + { + if (sum2 != 0 && sum2 < sum1) + { + //cout << "*++*\t"; + decreaseCount++; + } + } + //cout << "Last: " << lastValue << "\tMid: " << middleValue << "\tCurrent: " << currentValue; + //cout << "\tSum1: " << sum1 << "\tSum2: " << sum2 << "\n"; + lastValue = middleValue; + middleValue = currentValue; + sum2 = sum1; + } + cout << decreaseCount; + return 0; +}