Estoy intentando hacer años anteriores

This commit is contained in:
Daniel Cortés
2020-12-03 00:13:20 -03:00
parent f8a17e3fa0
commit 42edc83f90
5 changed files with 239 additions and 0 deletions

40
2019/day_1/tyranny.cc Normal file
View File

@@ -0,0 +1,40 @@
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
std::vector<int> read_input_file() {
std::ifstream file("input");
std::vector<int> data;
std::string line;
while(std::getline(file, line))
data.push_back(std::stoi(line));
return data;
}
int calculate_fuel(int mass) {
return (mass / 3) - 2;
}
int main() {
auto data = read_input_file();
int result_a = 0;
int result_b = 0;
for(auto &input : data) {
int fuel = calculate_fuel(input);
result_a += fuel;
while(fuel > 0){
result_b += fuel;
fuel = calculate_fuel(fuel);
}
}
std::cout << result_a << ", " << result_b << std::endl;
return 0;
}