AoC 2019 D1: The Tyranny of the Rocket Equation

C++ | Problem statement | Source code | Tags: Brute force

Back to AoC Index Next →

Part 1

Not much to say about this. Division rounds down by default in C++.

int fuel = mass / 3 - 2;
total += fuel;
cpp

Part 2

I bet there's a way to mathematically calculate the limit, but this at most takes log3(w)\log_3(w) iterations per module, so it's efficient enough.

while (fuel > 0) {
total += fuel;
fuel = fuel / 3 - 2;
}
cpp

Back to AoC Index Next →