day 5 part 2 was meh

This commit is contained in:
Nico 2022-12-05 21:35:44 +00:00
parent 57fd3d6b91
commit d0e1935855
1 changed files with 15 additions and 3 deletions

View File

@ -56,9 +56,21 @@ pub fn part_one(input: &str) -> Option<String> {
}
pub fn part_two(input: &str) -> Option<String> {
let _ = input;
let parts: Vec<&str> = input.split("\n\n").collect();
let mut stacks = parse_stacks(parts[0]);
let instructions = parse_instructions(parts[1]);
for i in instructions {
let mut new = Vec::new();
None
for _ in 0..(i.amount) {
let x = stacks[i.from-1].pop().unwrap();
new.insert(0,x);
}
stacks[i.to-1].append(&mut new);
}
Some(stacks.iter()
.map(| x | x[x.len()-1].to_string()) // stringify top element of every stack
.reduce(| x, y | x + &y).unwrap()) // and merge into one big string
}
fn main() {
@ -80,6 +92,6 @@ mod tests {
#[test]
fn test_part_two() {
let input = advent_of_code::read_file("examples", 5);
assert_eq!(part_two(&input), None);
assert_eq!(part_two(&input), Some("MCD".to_string()));
}
}