Piss poor attempt at AoC 2021 and I'm 3 years late publishing it :/

This commit is contained in:
Gnarwhal 2024-10-06 21:15:16 +00:00
parent 426e842536
commit c69deb2ae7
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174
9 changed files with 2344 additions and 0 deletions

54
2021/days/day1.cpp Normal file
View file

@ -0,0 +1,54 @@
/*****************************
*
* 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;
}
}