mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-26 05:10:32 +01:00
27 lines
562 B
C++
27 lines
562 B
C++
#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) {
|
|
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) {
|
|
int total = 0;
|
|
for (int current; input >> current;) {
|
|
for (int fuel = required(current); fuel > 0; fuel = required(fuel)) {
|
|
total += fuel;
|
|
}
|
|
}
|
|
|
|
output << total << std::endl;
|
|
}
|