advent_of_code/2021/days/day1.cpp

55 lines
1.1 KiB
C++
Raw Permalink Normal View History

/*****************************
*
* Copyright (c) 2021 Gnarwhal
*
*****************************/
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include "../misc/types.hpp"
#include "../misc/print.hpp"
auto current_day() -> void {
{
auto line = std::string();
auto file = std::ifstream("inputs/day1.input");
getline(file, line);
auto value = stoi(line);
auto increases = 0;
while (getline(file, line)) {
auto new_value = stoi(line);
increases += new_value > value;
value = new_value;
}
std::cout << increases << std::endl;
}
{
auto line = std::string();
auto file = std::ifstream("inputs/day1.input");
getline(file, line);
auto index = 2;
auto values = std::vector<i32>{ 0, 0 };
while (getline(file, line)) {
auto new_value = stoi(line);
values.push_back(0);
values[index - 2] += new_value;
values[index - 1] += new_value;
values[index ] += new_value;
++index;
}
auto increases = 0;
for (auto i = 3; i < values.size(); ++i) {
increases += values[i - 1] < values[i];
}
std::cout << increases << std::endl;
}
}