Day 5 Part 2.
This commit is contained in:
parent
b6c1733c21
commit
935f2a3ad4
1 changed files with 6 additions and 2 deletions
|
@ -66,7 +66,7 @@ fn analyse(str: &String) -> (u32, Vec<(u32, u32, u32)>, Vec<Vec<char>>) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn first_part(cmd: &Vec<(u32, u32, u32)>, crates: &Vec<Vec<char>>) -> String
|
fn part(part_num: i32, cmd: &Vec<(u32, u32, u32)>, crates: &Vec<Vec<char>>) -> String
|
||||||
{
|
{
|
||||||
// Algorithm
|
// Algorithm
|
||||||
let mut boxes = crates.clone();
|
let mut boxes = crates.clone();
|
||||||
|
@ -76,6 +76,9 @@ fn first_part(cmd: &Vec<(u32, u32, u32)>, crates: &Vec<Vec<char>>) -> String
|
||||||
moving_crates.push(boxes[(operation.1-1) as usize].last().unwrap().to_owned());
|
moving_crates.push(boxes[(operation.1-1) as usize].last().unwrap().to_owned());
|
||||||
boxes[(operation.1-1) as usize].pop();
|
boxes[(operation.1-1) as usize].pop();
|
||||||
}
|
}
|
||||||
|
if (operation.0 > 1) && (part_num ==2) {
|
||||||
|
moving_crates.reverse();
|
||||||
|
}
|
||||||
for mv in moving_crates {
|
for mv in moving_crates {
|
||||||
boxes[(operation.2-1) as usize].push(mv);
|
boxes[(operation.2-1) as usize].push(mv);
|
||||||
}
|
}
|
||||||
|
@ -93,5 +96,6 @@ fn main() {
|
||||||
let file_content = read_to_string("input").unwrap();
|
let file_content = read_to_string("input").unwrap();
|
||||||
let (max, cmd, crates) = analyse(&file_content);
|
let (max, cmd, crates) = analyse(&file_content);
|
||||||
println!("max = {}\ncmd = {:?}\ncrates = {:?}", max, cmd, crates);
|
println!("max = {}\ncmd = {:?}\ncrates = {:?}", max, cmd, crates);
|
||||||
println!("First part: {:?}", first_part(&cmd, &crates));
|
println!("First part: {:?}", part(1, &cmd, &crates));
|
||||||
|
println!("Second part: {:?}", part(2, &cmd, &crates));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue