add lookup table
This commit is contained in:
parent
aca62e1c44
commit
754b296abf
@ -58,6 +58,14 @@ impl SegmentSet {
|
|||||||
fn len(&self) -> u8 {
|
fn len(&self) -> u8 {
|
||||||
self.len
|
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 {
|
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 {
|
fn part1(screens: &[Screen]) -> usize {
|
||||||
screens.iter()
|
screens.iter()
|
||||||
.flat_map(|d| d.output.iter())
|
.flat_map(|d| d.output.iter())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user