diff --git a/advent_of_code/2022/5/main.cpp b/advent_of_code/2022/5/main.cpp index 361cb74..3739304 100644 --- a/advent_of_code/2022/5/main.cpp +++ b/advent_of_code/2022/5/main.cpp @@ -69,13 +69,28 @@ int main(){ int number_of_moves, source, target; tie(number_of_moves, source, target) = command; + // For part 1 use this: + + // while(number_of_moves > 0){ + // char crate = crate_stacks[source - 1].top(); + // crate_stacks[source - 1].pop(); + // crate_stacks[target - 1].push(crate); + + // number_of_moves--; + // } + + vector crates; while(number_of_moves > 0){ char crate = crate_stacks[source - 1].top(); crate_stacks[source - 1].pop(); - crate_stacks[target - 1].push(crate); + crates.push_back(crate); number_of_moves--; } + + for(int i = crates.size() - 1; i >= 0; i--){ + crate_stacks[target - 1].push(crates[i]); + } } // Print answer