From: Greg Burri Date: Tue, 13 Dec 2022 15:12:39 +0000 (+0100) Subject: Try to speed up day 5 X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=9a0270f5d20d688d7f8499920a226e644fbd705b;p=advent_of_code_2022.git Try to speed up day 5 --- diff --git a/src/day05.rs b/src/day05.rs index c502f3f..6cd1803 100644 --- a/src/day05.rs +++ b/src/day05.rs @@ -48,19 +48,19 @@ pub fn parse(s: &str) -> (Stacks, Vec) { } pub fn apply_moves_by_crate_mover_9000(stacks: &mut Stacks, moves: &[Move]) { - apply_moves(stacks, moves, true); + apply_moves::(stacks, moves); } pub fn apply_moves_by_crate_mover_9001(stacks: &mut Stacks, moves: &[Move]) { - apply_moves(stacks, moves, false); + apply_moves::(stacks, moves); } -fn apply_moves(stacks: &mut Stacks, moves: &[Move], reverse_stack: bool) { +fn apply_moves(stacks: &mut Stacks, moves: &[Move]) { for m in moves { let from = stacks.get_mut(m.from).unwrap(); let mut to_move = from.split_off(from.len() - m.n); - if reverse_stack { + if REVERSE_STACK { to_move.make_contiguous().reverse(); }