advent_of_code_2022/days/day05/src/part1.rs
Gabe Venberg 242989bb95 switched to workspaces.
This should let me make a cross-day library.
2023-11-19 20:32:41 -06:00

49 lines
1.1 KiB
Rust

use crate::utilities::*;
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()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_part1() {
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']);
}
}