Part 2
This commit is contained in:
parent
d46fd97fd9
commit
cf69f9f93d
|
@ -81,15 +81,36 @@ fn part1(input: &mut Input) -> Result {
|
||||||
r.trim().to_string()
|
r.trim().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(input: &Input) -> Result {
|
fn perform_moves2(crates: &mut Crates) {
|
||||||
"".to_string()
|
let stacks = &mut crates.stacks;
|
||||||
|
for Move { amount, from, to } in &crates.moves {
|
||||||
|
println!("move: {} {} {}", amount, from, to);
|
||||||
|
let l = stacks[*from].len();
|
||||||
|
println!("len: {:?}", l);
|
||||||
|
let ra = l - (*amount as usize)..l;
|
||||||
|
let mut popped: Vec<char> = stacks[*from].splice(ra, vec![]).collect();
|
||||||
|
stacks[*to].append(&mut popped);
|
||||||
|
println!("{:?}", stacks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn part2(input: &mut Input) -> Result {
|
||||||
|
println!("{:?}", input);
|
||||||
|
perform_moves2(input);
|
||||||
|
|
||||||
|
let mut r = String::from("");
|
||||||
|
for s in &input.stacks {
|
||||||
|
r.push(s.last().unwrap_or(&' ').clone())
|
||||||
|
}
|
||||||
|
r.trim().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let input_text = common::day_input(5);
|
let input_text = common::day_input(5);
|
||||||
eprintln!("{}\n\nAbove is your input file.\n\n", input_text);
|
eprintln!("{}\n\nAbove is your input file.\n\n", input_text);
|
||||||
let mut input = processed_input(&input_text);
|
let mut input = processed_input(&input_text);
|
||||||
common::show_answers(&part1(&mut input), &part2(&input))
|
let mut input2 = processed_input(&input_text);
|
||||||
|
common::show_answers(&part1(&mut input), &part2(&mut input2))
|
||||||
// common::show_both_answers(&both_parts(&input))
|
// common::show_both_answers(&both_parts(&input))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +137,7 @@ move 1 from 1 to 2";
|
||||||
let mut input = processed_input(TEST_INPUT);
|
let mut input = processed_input(TEST_INPUT);
|
||||||
assert_eq!(part1(&mut input), "CMZ");
|
assert_eq!(part1(&mut input), "CMZ");
|
||||||
let mut input = processed_input(TEST_INPUT);
|
let mut input = processed_input(TEST_INPUT);
|
||||||
assert_eq!(part2(&input), "");
|
assert_eq!(part2(&mut input), "MCD");
|
||||||
// assert_eq!(both_parts(&input), (0, 0));
|
// assert_eq!(both_parts(&input), (0, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue