Day 1 Complete

This commit is contained in:
Blizzard Finnegan 2021-12-06 10:50:41 -05:00
parent ab40994195
commit ea4c7bb3f1
6 changed files with 68 additions and 0 deletions

10
day1/data/testInput.txt Normal file
View file

@ -0,0 +1,10 @@
103
106
107
110
121
132
147
148
144
141

BIN
day1/day1Part1 Executable file

Binary file not shown.

24
day1/day1Part1.cpp Normal file
View file

@ -0,0 +1,24 @@
#include <iostream>
#include <fstream>
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;
}

BIN
day1/day1Part2 Executable file

Binary file not shown.

34
day1/day1Part2.cpp Normal file
View file

@ -0,0 +1,34 @@
#include <iostream>
#include <fstream>
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;
}