From: Greg Burri Date: Tue, 13 Dec 2022 15:12:39 +0000 (+0100) Subject: Try to speed up day 5 X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=7236d5fc0b339082a8048e55d8641aa0ea3a58a7;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(); }