start year 2022 day 05

This commit is contained in:
2023-11-25 14:01:58 +01:00
parent 03cbaa117f
commit 11ac320683
4 changed files with 578 additions and 0 deletions

View File

@@ -16,4 +16,5 @@ pub mod year2022 {
pub mod day02;
pub mod day03;
pub mod day04;
pub mod day05;
}

View File

@@ -86,5 +86,6 @@ fn year2022() -> Vec<Solution> {
solution!(year2022, day02),
solution!(year2022, day03),
solution!(year2022, day04),
solution!(year2022, day05),
]
}

64
src/year2022/day05.rs Normal file
View 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()
)
}