day 5 done
This commit is contained in:
parent
083cdabb2f
commit
04520e62ce
|
@ -2,3 +2,4 @@ pub mod problem_01;
|
||||||
pub mod problem_02;
|
pub mod problem_02;
|
||||||
pub mod problem_03;
|
pub mod problem_03;
|
||||||
pub mod problem_04;
|
pub mod problem_04;
|
||||||
|
pub mod problem_05;
|
||||||
|
|
|
@ -2,6 +2,7 @@ use taoc2022::problem_01;
|
||||||
use taoc2022::problem_02;
|
use taoc2022::problem_02;
|
||||||
use taoc2022::problem_03;
|
use taoc2022::problem_03;
|
||||||
use taoc2022::problem_04;
|
use taoc2022::problem_04;
|
||||||
|
use taoc2022::problem_05;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("== Problem 01 ==");
|
println!("== Problem 01 ==");
|
||||||
|
@ -16,4 +17,7 @@ fn main() {
|
||||||
println!("== Problem 04 ==");
|
println!("== Problem 04 ==");
|
||||||
println!("= a: {}", problem_04::solution_a());
|
println!("= a: {}", problem_04::solution_a());
|
||||||
println!("= b: {}", problem_04::solution_b());
|
println!("= b: {}", problem_04::solution_b());
|
||||||
|
println!("== Problem 05 ==");
|
||||||
|
println!("= a: {}", problem_05::solution_a());
|
||||||
|
println!("= b: {}", problem_05::solution_b());
|
||||||
}
|
}
|
||||||
|
|
111
src/problem_05/description.txt
Normal file
111
src/problem_05/description.txt
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
--- Day 5: Supply Stacks ---
|
||||||
|
|
||||||
|
The expedition can depart as soon as the final supplies have been unloaded from the ships. Supplies are stored in stacks of marked crates, but because the needed supplies are buried under many other crates, the crates need to be rearranged.
|
||||||
|
|
||||||
|
The ship has a giant cargo crane capable of moving crates between stacks. To ensure none of the crates get crushed or fall over, the crane operator will rearrange them in a series of carefully-planned steps. After the crates are rearranged, the desired crates will be at the top of each stack.
|
||||||
|
|
||||||
|
The Elves don't want to interrupt the crane operator during this delicate procedure, but they forgot to ask her which crate will end up where, and they want to be ready to unload them as soon as possible so they can embark.
|
||||||
|
|
||||||
|
They do, however, have a drawing of the starting stacks of crates and the rearrangement procedure (your puzzle input). For example:
|
||||||
|
|
||||||
|
[D]
|
||||||
|
[N] [C]
|
||||||
|
[Z] [M] [P]
|
||||||
|
1 2 3
|
||||||
|
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 3 from 1 to 3
|
||||||
|
move 2 from 2 to 1
|
||||||
|
move 1 from 1 to 2
|
||||||
|
|
||||||
|
In this example, there are three stacks of crates. Stack 1 contains two crates: crate Z is on the bottom, and crate N is on top. Stack 2 contains three crates; from bottom to top, they are crates M, C, and D. Finally, stack 3 contains a single crate, P.
|
||||||
|
|
||||||
|
Then, the rearrangement procedure is given. In each step of the procedure, a quantity of crates is moved from one stack to a different stack. In the first step of the above rearrangement procedure, one crate is moved from stack 2 to stack 1, resulting in this configuration:
|
||||||
|
|
||||||
|
[D]
|
||||||
|
[N] [C]
|
||||||
|
[Z] [M] [P]
|
||||||
|
1 2 3
|
||||||
|
|
||||||
|
In the second step, three crates are moved from stack 1 to stack 3. Crates are moved one at a time, so the first crate to be moved (D) ends up below the second and third crates:
|
||||||
|
|
||||||
|
[Z]
|
||||||
|
[N]
|
||||||
|
[C] [D]
|
||||||
|
[M] [P]
|
||||||
|
1 2 3
|
||||||
|
|
||||||
|
Then, both crates are moved from stack 2 to stack 1. Again, because crates are moved one at a time, crate C ends up below crate M:
|
||||||
|
|
||||||
|
[Z]
|
||||||
|
[N]
|
||||||
|
[M] [D]
|
||||||
|
[C] [P]
|
||||||
|
1 2 3
|
||||||
|
|
||||||
|
Finally, one crate is moved from stack 1 to stack 2:
|
||||||
|
|
||||||
|
[Z]
|
||||||
|
[N]
|
||||||
|
[D]
|
||||||
|
[C] [M] [P]
|
||||||
|
1 2 3
|
||||||
|
|
||||||
|
The Elves just need to know which crate will end up on top of each stack; in this example, the top crates are C in stack 1, M in stack 2, and Z in stack 3, so you should combine these together and give the Elves the message CMZ.
|
||||||
|
|
||||||
|
After the rearrangement procedure completes, what crate ends up on top of each stack?
|
||||||
|
|
||||||
|
Your puzzle answer was SBPQRSCDF.
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
As you watch the crane operator expertly rearrange the crates, you notice the process isn't following your prediction.
|
||||||
|
|
||||||
|
Some mud was covering the writing on the side of the crane, and you quickly wipe it away. The crane isn't a CrateMover 9000 - it's a CrateMover 9001.
|
||||||
|
|
||||||
|
The CrateMover 9001 is notable for many new and exciting features: air conditioning, leather seats, an extra cup holder, and the ability to pick up and move multiple crates at once.
|
||||||
|
|
||||||
|
Again considering the example above, the crates begin in the same configuration:
|
||||||
|
|
||||||
|
[D]
|
||||||
|
[N] [C]
|
||||||
|
[Z] [M] [P]
|
||||||
|
1 2 3
|
||||||
|
|
||||||
|
Moving a single crate from stack 2 to stack 1 behaves the same as before:
|
||||||
|
|
||||||
|
[D]
|
||||||
|
[N] [C]
|
||||||
|
[Z] [M] [P]
|
||||||
|
1 2 3
|
||||||
|
|
||||||
|
However, the action of moving three crates from stack 1 to stack 3 means that those three moved crates stay in the same order, resulting in this new configuration:
|
||||||
|
|
||||||
|
[D]
|
||||||
|
[N]
|
||||||
|
[C] [Z]
|
||||||
|
[M] [P]
|
||||||
|
1 2 3
|
||||||
|
|
||||||
|
Next, as both crates are moved from stack 2 to stack 1, they retain their order as well:
|
||||||
|
|
||||||
|
[D]
|
||||||
|
[N]
|
||||||
|
[C] [Z]
|
||||||
|
[M] [P]
|
||||||
|
1 2 3
|
||||||
|
|
||||||
|
Finally, a single crate is still moved from stack 1 to stack 2, but now it's crate C that gets moved:
|
||||||
|
|
||||||
|
[D]
|
||||||
|
[N]
|
||||||
|
[Z]
|
||||||
|
[M] [C] [P]
|
||||||
|
1 2 3
|
||||||
|
|
||||||
|
In this example, the CrateMover 9001 has put the crates in a totally different order: MCD.
|
||||||
|
|
||||||
|
Before the rearrangement process finishes, update your simulation so that the Elves know where they should stand to be ready to unload the final supplies. After the rearrangement procedure completes, what crate ends up on top of each stack?
|
||||||
|
|
||||||
|
Your puzzle answer was RGLVRCQSB.
|
||||||
|
|
||||||
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
514
src/problem_05/input.txt
Normal file
514
src/problem_05/input.txt
Normal file
|
@ -0,0 +1,514 @@
|
||||||
|
[V] [B] [F]
|
||||||
|
[N] [Q] [W] [R] [B]
|
||||||
|
[F] [D] [S] [B] [L] [P]
|
||||||
|
[S] [J] [C] [F] [C] [D] [G]
|
||||||
|
[M] [M] [H] [L] [P] [N] [P] [V]
|
||||||
|
[P] [L] [D] [C] [T] [Q] [R] [S] [J]
|
||||||
|
[H] [R] [Q] [S] [V] [R] [V] [Z] [S]
|
||||||
|
[J] [S] [N] [R] [M] [T] [G] [C] [D]
|
||||||
|
1 2 3 4 5 6 7 8 9
|
||||||
|
|
||||||
|
move 1 from 8 to 4
|
||||||
|
move 1 from 7 to 8
|
||||||
|
move 1 from 6 to 3
|
||||||
|
move 2 from 6 to 5
|
||||||
|
move 8 from 5 to 1
|
||||||
|
move 5 from 3 to 8
|
||||||
|
move 1 from 7 to 8
|
||||||
|
move 8 from 1 to 2
|
||||||
|
move 3 from 3 to 9
|
||||||
|
move 13 from 8 to 7
|
||||||
|
move 2 from 1 to 2
|
||||||
|
move 1 from 6 to 2
|
||||||
|
move 2 from 1 to 7
|
||||||
|
move 4 from 4 to 2
|
||||||
|
move 10 from 9 to 4
|
||||||
|
move 7 from 4 to 1
|
||||||
|
move 1 from 6 to 7
|
||||||
|
move 2 from 4 to 5
|
||||||
|
move 1 from 5 to 2
|
||||||
|
move 1 from 5 to 8
|
||||||
|
move 3 from 1 to 5
|
||||||
|
move 2 from 4 to 6
|
||||||
|
move 2 from 6 to 4
|
||||||
|
move 2 from 4 to 5
|
||||||
|
move 5 from 1 to 5
|
||||||
|
move 1 from 9 to 5
|
||||||
|
move 1 from 8 to 5
|
||||||
|
move 14 from 2 to 6
|
||||||
|
move 12 from 7 to 4
|
||||||
|
move 4 from 6 to 7
|
||||||
|
move 3 from 6 to 4
|
||||||
|
move 4 from 4 to 9
|
||||||
|
move 2 from 4 to 6
|
||||||
|
move 2 from 9 to 3
|
||||||
|
move 9 from 4 to 3
|
||||||
|
move 2 from 1 to 6
|
||||||
|
move 5 from 7 to 3
|
||||||
|
move 4 from 7 to 8
|
||||||
|
move 2 from 6 to 7
|
||||||
|
move 3 from 6 to 7
|
||||||
|
move 10 from 5 to 8
|
||||||
|
move 8 from 8 to 9
|
||||||
|
move 10 from 9 to 7
|
||||||
|
move 12 from 7 to 5
|
||||||
|
move 1 from 1 to 5
|
||||||
|
move 3 from 7 to 2
|
||||||
|
move 10 from 3 to 7
|
||||||
|
move 6 from 5 to 7
|
||||||
|
move 2 from 6 to 1
|
||||||
|
move 12 from 2 to 7
|
||||||
|
move 3 from 3 to 1
|
||||||
|
move 1 from 6 to 5
|
||||||
|
move 10 from 5 to 7
|
||||||
|
move 3 from 3 to 4
|
||||||
|
move 34 from 7 to 1
|
||||||
|
move 2 from 6 to 9
|
||||||
|
move 1 from 6 to 3
|
||||||
|
move 3 from 1 to 3
|
||||||
|
move 1 from 7 to 3
|
||||||
|
move 3 from 3 to 6
|
||||||
|
move 1 from 4 to 3
|
||||||
|
move 22 from 1 to 6
|
||||||
|
move 2 from 9 to 7
|
||||||
|
move 2 from 4 to 9
|
||||||
|
move 12 from 6 to 8
|
||||||
|
move 1 from 7 to 6
|
||||||
|
move 4 from 8 to 2
|
||||||
|
move 1 from 7 to 1
|
||||||
|
move 6 from 8 to 9
|
||||||
|
move 1 from 2 to 5
|
||||||
|
move 1 from 2 to 7
|
||||||
|
move 13 from 1 to 2
|
||||||
|
move 2 from 3 to 1
|
||||||
|
move 4 from 7 to 5
|
||||||
|
move 3 from 9 to 4
|
||||||
|
move 1 from 1 to 8
|
||||||
|
move 4 from 5 to 2
|
||||||
|
move 12 from 6 to 2
|
||||||
|
move 3 from 1 to 3
|
||||||
|
move 1 from 4 to 1
|
||||||
|
move 9 from 8 to 5
|
||||||
|
move 6 from 5 to 7
|
||||||
|
move 2 from 4 to 5
|
||||||
|
move 5 from 9 to 6
|
||||||
|
move 5 from 3 to 7
|
||||||
|
move 30 from 2 to 6
|
||||||
|
move 11 from 7 to 9
|
||||||
|
move 36 from 6 to 3
|
||||||
|
move 10 from 9 to 3
|
||||||
|
move 1 from 6 to 5
|
||||||
|
move 3 from 5 to 2
|
||||||
|
move 2 from 5 to 2
|
||||||
|
move 28 from 3 to 4
|
||||||
|
move 6 from 4 to 1
|
||||||
|
move 1 from 2 to 3
|
||||||
|
move 2 from 5 to 2
|
||||||
|
move 6 from 1 to 7
|
||||||
|
move 1 from 1 to 6
|
||||||
|
move 6 from 3 to 5
|
||||||
|
move 6 from 7 to 2
|
||||||
|
move 1 from 6 to 4
|
||||||
|
move 2 from 2 to 6
|
||||||
|
move 8 from 2 to 1
|
||||||
|
move 3 from 2 to 4
|
||||||
|
move 2 from 3 to 4
|
||||||
|
move 4 from 3 to 4
|
||||||
|
move 1 from 6 to 1
|
||||||
|
move 2 from 1 to 8
|
||||||
|
move 1 from 6 to 4
|
||||||
|
move 1 from 9 to 3
|
||||||
|
move 2 from 5 to 4
|
||||||
|
move 1 from 8 to 7
|
||||||
|
move 1 from 7 to 9
|
||||||
|
move 1 from 3 to 5
|
||||||
|
move 1 from 8 to 6
|
||||||
|
move 34 from 4 to 9
|
||||||
|
move 13 from 9 to 8
|
||||||
|
move 1 from 8 to 2
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 4 from 5 to 1
|
||||||
|
move 9 from 8 to 7
|
||||||
|
move 11 from 1 to 3
|
||||||
|
move 1 from 4 to 2
|
||||||
|
move 1 from 6 to 7
|
||||||
|
move 1 from 9 to 4
|
||||||
|
move 1 from 4 to 1
|
||||||
|
move 1 from 5 to 3
|
||||||
|
move 5 from 7 to 8
|
||||||
|
move 1 from 2 to 5
|
||||||
|
move 1 from 5 to 1
|
||||||
|
move 21 from 9 to 5
|
||||||
|
move 19 from 3 to 4
|
||||||
|
move 17 from 4 to 6
|
||||||
|
move 2 from 8 to 4
|
||||||
|
move 2 from 6 to 8
|
||||||
|
move 2 from 6 to 9
|
||||||
|
move 2 from 7 to 6
|
||||||
|
move 1 from 4 to 9
|
||||||
|
move 6 from 5 to 6
|
||||||
|
move 1 from 9 to 8
|
||||||
|
move 8 from 5 to 7
|
||||||
|
move 15 from 6 to 2
|
||||||
|
move 1 from 9 to 7
|
||||||
|
move 2 from 1 to 6
|
||||||
|
move 3 from 4 to 7
|
||||||
|
move 1 from 1 to 6
|
||||||
|
move 3 from 5 to 4
|
||||||
|
move 2 from 5 to 6
|
||||||
|
move 2 from 4 to 1
|
||||||
|
move 13 from 7 to 8
|
||||||
|
move 2 from 6 to 4
|
||||||
|
move 3 from 2 to 4
|
||||||
|
move 2 from 7 to 6
|
||||||
|
move 5 from 4 to 6
|
||||||
|
move 4 from 2 to 6
|
||||||
|
move 1 from 1 to 9
|
||||||
|
move 18 from 8 to 3
|
||||||
|
move 1 from 4 to 5
|
||||||
|
move 1 from 2 to 7
|
||||||
|
move 15 from 3 to 1
|
||||||
|
move 1 from 5 to 1
|
||||||
|
move 3 from 3 to 4
|
||||||
|
move 1 from 5 to 4
|
||||||
|
move 1 from 5 to 6
|
||||||
|
move 1 from 6 to 8
|
||||||
|
move 2 from 8 to 2
|
||||||
|
move 3 from 1 to 8
|
||||||
|
move 6 from 2 to 8
|
||||||
|
move 1 from 7 to 6
|
||||||
|
move 12 from 8 to 5
|
||||||
|
move 2 from 9 to 6
|
||||||
|
move 6 from 1 to 5
|
||||||
|
move 9 from 5 to 3
|
||||||
|
move 1 from 2 to 8
|
||||||
|
move 20 from 6 to 9
|
||||||
|
move 3 from 6 to 7
|
||||||
|
move 1 from 7 to 1
|
||||||
|
move 7 from 3 to 4
|
||||||
|
move 2 from 7 to 2
|
||||||
|
move 1 from 8 to 7
|
||||||
|
move 8 from 4 to 1
|
||||||
|
move 11 from 1 to 7
|
||||||
|
move 10 from 7 to 6
|
||||||
|
move 2 from 4 to 9
|
||||||
|
move 21 from 9 to 3
|
||||||
|
move 6 from 5 to 9
|
||||||
|
move 6 from 3 to 2
|
||||||
|
move 1 from 4 to 5
|
||||||
|
move 1 from 7 to 9
|
||||||
|
move 8 from 3 to 2
|
||||||
|
move 9 from 2 to 1
|
||||||
|
move 14 from 1 to 6
|
||||||
|
move 1 from 1 to 7
|
||||||
|
move 4 from 3 to 8
|
||||||
|
move 3 from 8 to 7
|
||||||
|
move 5 from 7 to 4
|
||||||
|
move 3 from 6 to 9
|
||||||
|
move 2 from 3 to 7
|
||||||
|
move 3 from 5 to 6
|
||||||
|
move 1 from 5 to 6
|
||||||
|
move 2 from 7 to 9
|
||||||
|
move 1 from 8 to 3
|
||||||
|
move 22 from 6 to 5
|
||||||
|
move 3 from 9 to 4
|
||||||
|
move 3 from 6 to 1
|
||||||
|
move 5 from 4 to 6
|
||||||
|
move 9 from 2 to 8
|
||||||
|
move 4 from 6 to 1
|
||||||
|
move 1 from 3 to 2
|
||||||
|
move 1 from 2 to 3
|
||||||
|
move 6 from 8 to 1
|
||||||
|
move 2 from 4 to 3
|
||||||
|
move 10 from 1 to 7
|
||||||
|
move 2 from 8 to 7
|
||||||
|
move 1 from 9 to 6
|
||||||
|
move 4 from 3 to 5
|
||||||
|
move 1 from 8 to 3
|
||||||
|
move 4 from 9 to 8
|
||||||
|
move 1 from 4 to 3
|
||||||
|
move 1 from 3 to 8
|
||||||
|
move 3 from 7 to 6
|
||||||
|
move 1 from 1 to 5
|
||||||
|
move 10 from 5 to 9
|
||||||
|
move 5 from 6 to 4
|
||||||
|
move 5 from 8 to 5
|
||||||
|
move 4 from 9 to 8
|
||||||
|
move 3 from 3 to 9
|
||||||
|
move 2 from 8 to 6
|
||||||
|
move 5 from 7 to 5
|
||||||
|
move 1 from 4 to 1
|
||||||
|
move 1 from 1 to 2
|
||||||
|
move 2 from 8 to 6
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 1 from 7 to 2
|
||||||
|
move 1 from 1 to 5
|
||||||
|
move 28 from 5 to 9
|
||||||
|
move 3 from 6 to 1
|
||||||
|
move 1 from 6 to 9
|
||||||
|
move 1 from 2 to 9
|
||||||
|
move 2 from 1 to 2
|
||||||
|
move 2 from 7 to 5
|
||||||
|
move 1 from 7 to 5
|
||||||
|
move 1 from 2 to 5
|
||||||
|
move 3 from 1 to 9
|
||||||
|
move 1 from 5 to 8
|
||||||
|
move 15 from 9 to 2
|
||||||
|
move 11 from 9 to 4
|
||||||
|
move 11 from 4 to 7
|
||||||
|
move 2 from 4 to 1
|
||||||
|
move 7 from 7 to 8
|
||||||
|
move 1 from 1 to 4
|
||||||
|
move 20 from 9 to 1
|
||||||
|
move 2 from 7 to 8
|
||||||
|
move 1 from 4 to 6
|
||||||
|
move 1 from 6 to 2
|
||||||
|
move 2 from 7 to 5
|
||||||
|
move 1 from 9 to 6
|
||||||
|
move 1 from 4 to 9
|
||||||
|
move 4 from 5 to 2
|
||||||
|
move 1 from 6 to 8
|
||||||
|
move 1 from 4 to 9
|
||||||
|
move 11 from 8 to 3
|
||||||
|
move 1 from 1 to 9
|
||||||
|
move 1 from 5 to 9
|
||||||
|
move 1 from 2 to 6
|
||||||
|
move 4 from 9 to 8
|
||||||
|
move 4 from 8 to 7
|
||||||
|
move 10 from 1 to 6
|
||||||
|
move 7 from 1 to 5
|
||||||
|
move 8 from 3 to 4
|
||||||
|
move 2 from 3 to 5
|
||||||
|
move 3 from 7 to 4
|
||||||
|
move 1 from 4 to 5
|
||||||
|
move 2 from 1 to 6
|
||||||
|
move 9 from 2 to 6
|
||||||
|
move 1 from 7 to 9
|
||||||
|
move 1 from 3 to 2
|
||||||
|
move 7 from 4 to 3
|
||||||
|
move 3 from 3 to 7
|
||||||
|
move 5 from 2 to 3
|
||||||
|
move 1 from 1 to 9
|
||||||
|
move 2 from 2 to 7
|
||||||
|
move 1 from 4 to 6
|
||||||
|
move 3 from 5 to 6
|
||||||
|
move 4 from 7 to 6
|
||||||
|
move 1 from 7 to 4
|
||||||
|
move 1 from 4 to 7
|
||||||
|
move 1 from 2 to 8
|
||||||
|
move 1 from 7 to 1
|
||||||
|
move 27 from 6 to 2
|
||||||
|
move 1 from 4 to 1
|
||||||
|
move 7 from 5 to 7
|
||||||
|
move 1 from 4 to 1
|
||||||
|
move 1 from 8 to 3
|
||||||
|
move 3 from 7 to 3
|
||||||
|
move 2 from 1 to 6
|
||||||
|
move 2 from 9 to 1
|
||||||
|
move 18 from 2 to 1
|
||||||
|
move 2 from 7 to 5
|
||||||
|
move 12 from 3 to 4
|
||||||
|
move 1 from 5 to 6
|
||||||
|
move 3 from 6 to 1
|
||||||
|
move 24 from 1 to 8
|
||||||
|
move 9 from 2 to 4
|
||||||
|
move 3 from 2 to 1
|
||||||
|
move 2 from 6 to 3
|
||||||
|
move 1 from 6 to 9
|
||||||
|
move 1 from 5 to 6
|
||||||
|
move 1 from 6 to 2
|
||||||
|
move 1 from 1 to 7
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 1 from 1 to 2
|
||||||
|
move 3 from 7 to 2
|
||||||
|
move 2 from 1 to 4
|
||||||
|
move 8 from 4 to 5
|
||||||
|
move 22 from 8 to 1
|
||||||
|
move 1 from 8 to 1
|
||||||
|
move 13 from 4 to 1
|
||||||
|
move 1 from 8 to 5
|
||||||
|
move 3 from 3 to 1
|
||||||
|
move 1 from 2 to 7
|
||||||
|
move 38 from 1 to 6
|
||||||
|
move 27 from 6 to 1
|
||||||
|
move 2 from 2 to 9
|
||||||
|
move 3 from 9 to 8
|
||||||
|
move 2 from 8 to 6
|
||||||
|
move 1 from 8 to 3
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 1 from 3 to 6
|
||||||
|
move 1 from 2 to 3
|
||||||
|
move 1 from 7 to 6
|
||||||
|
move 7 from 6 to 3
|
||||||
|
move 20 from 1 to 4
|
||||||
|
move 6 from 1 to 6
|
||||||
|
move 17 from 4 to 7
|
||||||
|
move 3 from 6 to 5
|
||||||
|
move 14 from 7 to 9
|
||||||
|
move 8 from 5 to 7
|
||||||
|
move 3 from 1 to 6
|
||||||
|
move 3 from 3 to 1
|
||||||
|
move 2 from 4 to 1
|
||||||
|
move 4 from 5 to 1
|
||||||
|
move 9 from 6 to 2
|
||||||
|
move 3 from 6 to 4
|
||||||
|
move 4 from 7 to 8
|
||||||
|
move 4 from 1 to 6
|
||||||
|
move 2 from 3 to 1
|
||||||
|
move 6 from 6 to 7
|
||||||
|
move 4 from 8 to 7
|
||||||
|
move 4 from 2 to 1
|
||||||
|
move 4 from 2 to 3
|
||||||
|
move 4 from 9 to 5
|
||||||
|
move 8 from 9 to 5
|
||||||
|
move 1 from 9 to 5
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 16 from 7 to 2
|
||||||
|
move 10 from 2 to 9
|
||||||
|
move 11 from 9 to 8
|
||||||
|
move 4 from 3 to 5
|
||||||
|
move 3 from 1 to 4
|
||||||
|
move 13 from 5 to 7
|
||||||
|
move 10 from 8 to 5
|
||||||
|
move 2 from 1 to 5
|
||||||
|
move 11 from 7 to 4
|
||||||
|
move 2 from 3 to 6
|
||||||
|
move 3 from 7 to 6
|
||||||
|
move 1 from 3 to 2
|
||||||
|
move 1 from 1 to 8
|
||||||
|
move 2 from 8 to 4
|
||||||
|
move 3 from 1 to 2
|
||||||
|
move 4 from 6 to 1
|
||||||
|
move 7 from 1 to 9
|
||||||
|
move 1 from 6 to 7
|
||||||
|
move 2 from 5 to 8
|
||||||
|
move 1 from 2 to 9
|
||||||
|
move 1 from 7 to 8
|
||||||
|
move 5 from 5 to 8
|
||||||
|
move 1 from 2 to 3
|
||||||
|
move 4 from 2 to 5
|
||||||
|
move 17 from 4 to 1
|
||||||
|
move 10 from 5 to 9
|
||||||
|
move 2 from 4 to 2
|
||||||
|
move 2 from 4 to 1
|
||||||
|
move 1 from 4 to 9
|
||||||
|
move 1 from 3 to 7
|
||||||
|
move 1 from 7 to 8
|
||||||
|
move 12 from 9 to 2
|
||||||
|
move 1 from 2 to 4
|
||||||
|
move 1 from 4 to 1
|
||||||
|
move 1 from 1 to 9
|
||||||
|
move 1 from 8 to 1
|
||||||
|
move 8 from 8 to 3
|
||||||
|
move 2 from 5 to 1
|
||||||
|
move 3 from 1 to 9
|
||||||
|
move 1 from 2 to 6
|
||||||
|
move 4 from 3 to 7
|
||||||
|
move 1 from 7 to 6
|
||||||
|
move 10 from 9 to 2
|
||||||
|
move 1 from 5 to 9
|
||||||
|
move 1 from 9 to 3
|
||||||
|
move 17 from 1 to 6
|
||||||
|
move 2 from 1 to 2
|
||||||
|
move 11 from 6 to 7
|
||||||
|
move 2 from 2 to 9
|
||||||
|
move 2 from 9 to 5
|
||||||
|
move 12 from 7 to 9
|
||||||
|
move 20 from 2 to 7
|
||||||
|
move 5 from 9 to 5
|
||||||
|
move 21 from 7 to 1
|
||||||
|
move 2 from 6 to 4
|
||||||
|
move 11 from 1 to 4
|
||||||
|
move 5 from 4 to 6
|
||||||
|
move 1 from 7 to 8
|
||||||
|
move 5 from 9 to 3
|
||||||
|
move 5 from 2 to 8
|
||||||
|
move 3 from 9 to 3
|
||||||
|
move 2 from 8 to 7
|
||||||
|
move 2 from 1 to 7
|
||||||
|
move 10 from 6 to 3
|
||||||
|
move 1 from 2 to 6
|
||||||
|
move 2 from 8 to 5
|
||||||
|
move 1 from 6 to 5
|
||||||
|
move 2 from 4 to 9
|
||||||
|
move 1 from 4 to 5
|
||||||
|
move 8 from 1 to 6
|
||||||
|
move 4 from 4 to 8
|
||||||
|
move 6 from 8 to 4
|
||||||
|
move 21 from 3 to 9
|
||||||
|
move 5 from 9 to 2
|
||||||
|
move 4 from 7 to 9
|
||||||
|
move 22 from 9 to 3
|
||||||
|
move 9 from 6 to 4
|
||||||
|
move 2 from 2 to 6
|
||||||
|
move 2 from 2 to 1
|
||||||
|
move 2 from 5 to 7
|
||||||
|
move 7 from 5 to 4
|
||||||
|
move 22 from 4 to 2
|
||||||
|
move 2 from 5 to 4
|
||||||
|
move 16 from 2 to 5
|
||||||
|
move 2 from 6 to 2
|
||||||
|
move 13 from 3 to 4
|
||||||
|
move 5 from 5 to 7
|
||||||
|
move 15 from 4 to 7
|
||||||
|
move 3 from 2 to 3
|
||||||
|
move 3 from 2 to 5
|
||||||
|
move 1 from 1 to 2
|
||||||
|
move 1 from 2 to 4
|
||||||
|
move 6 from 5 to 9
|
||||||
|
move 4 from 3 to 6
|
||||||
|
move 2 from 5 to 9
|
||||||
|
move 1 from 2 to 7
|
||||||
|
move 1 from 1 to 9
|
||||||
|
move 2 from 4 to 5
|
||||||
|
move 19 from 7 to 8
|
||||||
|
move 1 from 6 to 5
|
||||||
|
move 1 from 5 to 1
|
||||||
|
move 1 from 9 to 4
|
||||||
|
move 5 from 8 to 1
|
||||||
|
move 3 from 8 to 1
|
||||||
|
move 7 from 5 to 6
|
||||||
|
move 3 from 7 to 1
|
||||||
|
move 1 from 2 to 5
|
||||||
|
move 4 from 9 to 8
|
||||||
|
move 2 from 5 to 6
|
||||||
|
move 10 from 1 to 4
|
||||||
|
move 1 from 7 to 2
|
||||||
|
move 6 from 3 to 4
|
||||||
|
move 9 from 4 to 3
|
||||||
|
move 2 from 2 to 8
|
||||||
|
move 2 from 9 to 5
|
||||||
|
move 5 from 8 to 3
|
||||||
|
move 1 from 1 to 5
|
||||||
|
move 2 from 5 to 6
|
||||||
|
move 1 from 1 to 7
|
||||||
|
move 2 from 9 to 7
|
||||||
|
move 8 from 4 to 7
|
||||||
|
move 3 from 3 to 9
|
||||||
|
move 4 from 6 to 3
|
||||||
|
move 1 from 5 to 3
|
||||||
|
move 1 from 7 to 2
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 1 from 6 to 5
|
||||||
|
move 1 from 5 to 2
|
||||||
|
move 10 from 7 to 4
|
||||||
|
move 10 from 4 to 1
|
||||||
|
move 10 from 1 to 8
|
||||||
|
move 1 from 9 to 6
|
||||||
|
move 1 from 1 to 4
|
||||||
|
move 11 from 8 to 1
|
||||||
|
move 2 from 9 to 5
|
||||||
|
move 5 from 6 to 3
|
||||||
|
move 1 from 3 to 8
|
||||||
|
move 4 from 1 to 3
|
||||||
|
move 5 from 3 to 8
|
||||||
|
move 1 from 4 to 7
|
||||||
|
move 1 from 7 to 2
|
||||||
|
move 13 from 3 to 5
|
||||||
|
move 2 from 2 to 1
|
||||||
|
move 4 from 3 to 1
|
||||||
|
move 4 from 5 to 6
|
||||||
|
move 3 from 6 to 2
|
||||||
|
move 4 from 5 to 4
|
||||||
|
move 8 from 8 to 7
|
||||||
|
move 1 from 3 to 9
|
102
src/problem_05/mod.rs
Normal file
102
src/problem_05/mod.rs
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
|
static INPUT: &str = include_str!("input.txt");
|
||||||
|
|
||||||
|
type Instruction = (usize, usize, usize);
|
||||||
|
|
||||||
|
fn parse_input(s: &str) -> (Vec<VecDeque<char>>, Vec<Instruction>) {
|
||||||
|
let mut initial: Vec<VecDeque<char>> = vec![];
|
||||||
|
let mut instructions = vec![];
|
||||||
|
let mut input = s.lines();
|
||||||
|
for line in input.by_ref() {
|
||||||
|
if line.is_empty() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
initial.push(line.chars().collect());
|
||||||
|
}
|
||||||
|
initial.reverse();
|
||||||
|
initial.remove(0);
|
||||||
|
let num_columns = (initial[0].len() + 1) / 4;
|
||||||
|
let mut finals = vec![VecDeque::new(); num_columns];
|
||||||
|
for line in initial {
|
||||||
|
for (i, tower) in finals.iter_mut().enumerate().take(num_columns) {
|
||||||
|
let ind = (i * 4) + 1;
|
||||||
|
match line[ind] {
|
||||||
|
' ' => continue,
|
||||||
|
_ => tower.push_front(line[ind]),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for line in input {
|
||||||
|
let parsed_line = parse_instruction(line);
|
||||||
|
instructions.push(parsed_line);
|
||||||
|
}
|
||||||
|
(finals, instructions)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_instruction(s: &str) -> Instruction {
|
||||||
|
let binding = String::from(s)
|
||||||
|
.split(|c: char| c == ' ' || c.is_alphabetic())
|
||||||
|
.filter(|v| !v.is_empty())
|
||||||
|
.map(|c| c.parse().expect("not a number!"))
|
||||||
|
.collect::<Vec<usize>>();
|
||||||
|
let mut instructions = binding.iter();
|
||||||
|
match (
|
||||||
|
instructions.next(),
|
||||||
|
instructions.next(),
|
||||||
|
instructions.next(),
|
||||||
|
) {
|
||||||
|
(Some(a), Some(b), Some(c)) => (*a, *b, *c),
|
||||||
|
_ => panic!("error parsing input"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn execute_instructions_900(
|
||||||
|
instructions: Vec<Instruction>,
|
||||||
|
mut initial: Vec<VecDeque<char>>,
|
||||||
|
) -> Vec<VecDeque<char>> {
|
||||||
|
for (num, src, dst) in instructions {
|
||||||
|
for _i in 0..num {
|
||||||
|
match initial[src - 1].pop_front() {
|
||||||
|
Some(a) => initial[dst - 1].push_front(a),
|
||||||
|
_ => panic!("attempted to pop from empty stack"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
initial
|
||||||
|
}
|
||||||
|
|
||||||
|
fn execute_instructions_9001(
|
||||||
|
instructions: Vec<Instruction>,
|
||||||
|
mut initial: Vec<VecDeque<char>>,
|
||||||
|
) -> Vec<VecDeque<char>> {
|
||||||
|
for (num, src, dst) in instructions {
|
||||||
|
for i in 0..num {
|
||||||
|
match initial[src - 1].pop_front() {
|
||||||
|
Some(a) => initial[dst - 1].insert(i, a),
|
||||||
|
_ => panic!("attempted to pop from empty stack"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
initial
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn solution_a() -> String {
|
||||||
|
let (initial, instructions) = parse_input(INPUT);
|
||||||
|
let initial = execute_instructions_900(instructions, initial);
|
||||||
|
let mut result = String::new();
|
||||||
|
for tower in initial {
|
||||||
|
result.push(tower[0]);
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn solution_b() -> String {
|
||||||
|
let (initial, instructions) = parse_input(INPUT);
|
||||||
|
let initial = execute_instructions_9001(instructions, initial);
|
||||||
|
let mut result = String::new();
|
||||||
|
for tower in initial {
|
||||||
|
result.push(tower[0]);
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
Loading…
Reference in a new issue