start year 2022 day 05
This commit is contained in:
64
src/year2022/day05.rs
Normal file
64
src/year2022/day05.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::util::parse::ParseExt;
|
||||
|
||||
fn parse(input: &str) -> (BTreeMap<usize, Vec<char>>, Vec<[u32; 3]>) {
|
||||
let mut crates: BTreeMap<usize, Vec<char>> = BTreeMap::new();
|
||||
let mut moves = vec![];
|
||||
let (board, moveset) = input.split_once("\n\n\n").expect("must be there");
|
||||
|
||||
board.lines().for_each(|line| {
|
||||
if !line.contains('[') {
|
||||
return;
|
||||
}
|
||||
|
||||
line.chars()
|
||||
.enumerate()
|
||||
.filter(|(_idx, c)| c.is_ascii_uppercase())
|
||||
.for_each(|(idx, c)| {
|
||||
crates
|
||||
.entry(((idx - 4) / 4) + 1)
|
||||
.and_modify(|v| v.push(c))
|
||||
.or_insert(vec![]);
|
||||
});
|
||||
});
|
||||
crates.values_mut().for_each(|v| v.reverse());
|
||||
|
||||
let moves = moveset
|
||||
.lines()
|
||||
.map(|line| {
|
||||
let mut nums = line.u32s();
|
||||
[
|
||||
nums.next().expect("first num"),
|
||||
nums.next().expect("second num"),
|
||||
nums.next().expect("third num"),
|
||||
]
|
||||
})
|
||||
.collect();
|
||||
|
||||
(crates, moves)
|
||||
}
|
||||
|
||||
pub fn part1(input: &str) -> impl std::fmt::Display {
|
||||
""
|
||||
}
|
||||
|
||||
pub fn part2(input: &str) -> impl std::fmt::Display {
|
||||
""
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_part1() {
|
||||
assert_eq!(
|
||||
"2",
|
||||
part1("2-4,6-8\n2-3,4-5\n5-7,7-9\n2-8,3-7\n6-6,4-6\n2-6,4-8").to_string()
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_part2() {
|
||||
assert_eq!(
|
||||
"4",
|
||||
part2("2-4,6-8\n2-3,4-5\n5-7,7-9\n2-8,3-7\n6-6,4-6\n2-6,4-8").to_string()
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user