Day 3 part 2... My struggle in the first half made the second half bliss!
This commit is contained in:
parent
0837967a6b
commit
27a646f88f
@ -22,9 +22,21 @@ impl Solution for Day03 {
|
||||
|
||||
fn part2(
|
||||
&self,
|
||||
_input: &mut Vec<String>,
|
||||
input: &mut Vec<String>,
|
||||
) -> Result<Box<dyn std::fmt::Display>, Box<dyn std::error::Error>> {
|
||||
Ok(Box::new("Ready"))
|
||||
// Get data into a byte array
|
||||
let lines = input.iter().map(|s| s.as_bytes()).collect::<Vec<_>>();
|
||||
let mut symbols: HashMap<(usize, usize, char), Vec<usize>> = HashMap::new();
|
||||
|
||||
// Get the valid numbers from the input
|
||||
self.map_valid_nums(&lines, &mut symbols)?;
|
||||
|
||||
let ans: usize = symbols
|
||||
.iter()
|
||||
.filter(|(&(_, _, s), v)| s == '*' && v.len() == 2)
|
||||
.map(|(_, v)| v[0] * v[1])
|
||||
.sum();
|
||||
Ok(Box::new(ans))
|
||||
}
|
||||
|
||||
fn get_day(&self) -> u8 {
|
||||
@ -124,6 +136,6 @@ mod test {
|
||||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
assert_eq!(answer, "Ready");
|
||||
assert_eq!(answer, "467835");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user