Implement day 1.

This commit is contained in:
2019-12-01 10:50:27 +01:00
parent d0a1ca604d
commit b23b0999d6
2 changed files with 118 additions and 2 deletions

View File

@@ -1,10 +1,26 @@
#include <iostream>
#include "days.hpp"
static inline int required(int weight) {
return weight / 3 - 2;
}
void aoc2019::day01_part1(std::istream &input, std::ostream &output) {
output << "Not implemented\n";
int total = 0;
for (int current; input >> current;) {
total += required(current);
}
output << total << std::endl;
}
void aoc2019::day01_part2(std::istream &input, std::ostream &output) {
output << "Not implemented\n";
int total = 0;
for (int current; input >> current;) {
for (int fuel = required(current); fuel > 0; fuel = required(fuel)) {
total += fuel;
}
}
output << total << std::endl;
}