My attempts to solve puzzles of Advent of Code
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(2023): refactor day 3

Signed-off-by: Kaushik Chakraborty <git@kaushikc.org>

+1 -16
+1 -16
src/solutions/year_2023/day3.rs
··· 1 - use std::{collections::HashSet, str::Chars}; 1 + use std::collections::HashSet; 2 2 3 3 use aoc_lib::{create_solution, Input, Solver}; 4 4 5 5 #[derive(Debug, Clone)] 6 6 pub struct Day3 { 7 7 engine_schematic: EngineSchematic, 8 - part_numbers: Vec<u64>, 9 8 } 10 9 11 10 #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Hash)] ··· 51 50 }, 52 51 ]) 53 52 } 54 - } 55 - 56 - #[derive(Debug, Clone)] 57 - struct Digit { 58 - digit: char, 59 - point: Point, 60 53 } 61 54 62 55 #[derive(Debug, Clone)] ··· 112 105 #[derive(Debug, Clone)] 113 106 struct EngineSchematic { 114 107 special_chars: Vec<SpecialChar>, 115 - digits: Vec<Digit>, 116 108 numbers: Vec<Number>, 117 109 118 110 special_char_indices: HashSet<Point>, ··· 121 113 impl FromIterator<Vec<char>> for EngineSchematic { 122 114 fn from_iter<T: IntoIterator<Item = Vec<char>>>(iter: T) -> Self { 123 115 let mut special_chars = Vec::new(); 124 - let mut digits = Vec::new(); 125 116 let mut numbers = Vec::new(); 126 117 let mut current_number_string = String::new(); 127 118 let mut current_number = Number { ··· 132 123 for (x, row) in iter.into_iter().enumerate() { 133 124 for (y, c) in row.into_iter().enumerate() { 134 125 if c.is_digit(10) { 135 - digits.push(Digit { 136 - digit: c, 137 - point: Point { x, y }, 138 - }); 139 126 current_number.points.insert(Point { x, y }); 140 127 current_number_string.push(c); 141 128 } else { ··· 173 160 } 174 161 Self { 175 162 special_chars: special_chars.clone(), 176 - digits, 177 163 numbers, 178 164 special_char_indices: special_chars 179 165 .iter() ··· 218 204 .into_iter() 219 205 .map(|line| line.chars().collect::<Vec<_>>()) 220 206 .collect::<EngineSchematic>(), 221 - part_numbers: Vec::new(), 222 207 } 223 208 } 224 209 }