Skip to content

Commit ad36989

Browse files
committed
Use a lookup table for 2024 day 25 parsing
1 parent 824d343 commit ad36989

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

crates/year2024/src/day25.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@ pub struct Day25 {
77
keys: Vec<u32>,
88
}
99

10+
const LOOKUP: [Option<bool>; 256] = {
11+
let mut x = [None; 256];
12+
x['#' as usize] = Some(true);
13+
x['.' as usize] = Some(false);
14+
x
15+
};
16+
1017
impl Day25 {
1118
pub fn new(input: &str, _: InputType) -> Result<Self, InputError> {
1219
let mut locks = Vec::with_capacity(250);
1320
let mut keys = Vec::with_capacity(250);
1421

15-
for item in parser::one_of((b'.'.map(|_| false), b'#'.map(|_| true)))
22+
for item in parser::byte()
23+
.map_res(|b| LOOKUP[b as usize].ok_or("expected '.' or '#'"))
1624
.repeat_n::<5, _>(parser::noop())
1725
.repeat_n::<7, _>(parser::eol())
1826
.with_consumed()

0 commit comments

Comments
 (0)