add lookup table

This commit is contained in:
Joseph Montanaro 2021-12-09 15:38:15 -08:00
parent aca62e1c44
commit 754b296abf

View File

@ -58,6 +58,14 @@ impl SegmentSet {
fn len(&self) -> u8 {
self.len
}
fn union(&self, other: &Self) -> Self {
self.data | other.data
}
fn intersect(&self, other: &Self) -> Self {
self.data & other.data
}
}
impl FromStr for SegmentSet {
@ -95,6 +103,21 @@ impl FromStr for Screen {
}
const DIGIT_SEGMENTS = {
let segment_strs = [
"abcefg", "cf", "acdeg", "acdfg",
"bcdf", "abdfg", "abdefg", "acf",
"abcdefg", "abcdfg",
]
let sets = [SegmentSet::default(), 10]
for (i, s) in segment_strs.iter().enumerate() {
sets[i] = s.parse::<SegmentSet>().unwrap()
}
sets
}
fn part1(screens: &[Screen]) -> usize {
screens.iter()
.flat_map(|d| d.output.iter())