advent_of_code_2022/days/day05/src/part1.rs

49 lines
1.1 KiB
Rust
Raw Permalink Normal View History

2022-12-04 00:41:09 -06:00
use crate::utilities::*;
2022-12-05 01:48:20 -06:00
pub fn part1(input: &(WorkArea, Vec<Move>)) -> Vec<char> {
let (mut work_area, moves) = input.to_owned();
for r#move in moves {
work_area.apply_move_cratemover9000(&r#move)
}
work_area
.get_stacks()
.iter()
.map(|stack| stack.last().unwrap().to_owned())
.collect()
2022-12-04 00:41:09 -06:00
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_part1() {
2022-12-05 01:48:20 -06:00
let input = (
WorkArea::new(vec![vec!['Z', 'N'], vec!['M', 'C', 'D'], vec!['P']]),
vec![
Move {
to: 1,
from: 2,
number: 1,
},
Move {
to: 3,
from: 1,
number: 3,
},
Move {
to: 1,
from: 2,
number: 2,
},
Move {
to: 2,
from: 1,
number: 1,
},
],
);
assert_eq!(part1(&input), vec!['C', 'M', 'Z']);
2022-12-04 00:41:09 -06:00
}
}