Advent of Code 2021, see plus plus edition
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
794 B

3 years ago
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
3 years ago
int main(int argc, char *argv[])
{
3 years ago
if (argc <= 1) return 1;
vector<unsigned> numbers;
3 years ago
{
ifstream input(argv[1]);
if (!input.is_open()) return 1;
unsigned num;
while (input >> num) {
numbers.push_back(num);
}
3 years ago
}
unsigned part1 = 0;
for (size_t i = 1; i < numbers.size(); i++) {
if (numbers[i] > numbers[i-1]) part1++;
}
cout << part1 << endl;
unsigned part2 = 0;
for (size_t i = 4; i < numbers.size(); i++) {
unsigned win1 = numbers[i-1] + numbers[i-2] + numbers[i-3];
unsigned win2 = numbers[i] + numbers[i-1] + numbers[i-2];
if (win2 > win1) part2++;
}
cout << part2 << endl;
}