Merge branch 'main' of https://git.micosita.es/micosil/adventOfCode_2023
commit
5b2c2df628
|
|
@ -0,0 +1,85 @@
|
|||
use std::fs;
|
||||
|
||||
pub fn run_day3(){
|
||||
let contents = fs::read_to_string("input.txt")
|
||||
.expect("Could not load file");
|
||||
let part_one_result = part_one(&contents);
|
||||
}
|
||||
|
||||
struct SymbolPosition<'a> {
|
||||
x: usize,
|
||||
y: usize,
|
||||
char_map: &'a Vec<Vec<char>>
|
||||
}
|
||||
|
||||
impl SymbolPosition<'_> {
|
||||
fn explore_neighbours(&self) -> Vec<i32>{
|
||||
let mut found_numbers: Vec<i32> = Vec::new();
|
||||
|
||||
let neighbours: [SymbolPosition; 8] = [
|
||||
SymbolPosition{x: self.x - 1, y: self.y - 1, char_map: self.char_map},
|
||||
SymbolPosition{x: self.x , y: self.y - 1, char_map: self.char_map},
|
||||
SymbolPosition{x: self.x + 1, y: self.y - 1, char_map: self.char_map},
|
||||
SymbolPosition{x: self.x - 1, y: self.y , char_map: self.char_map},
|
||||
SymbolPosition{x: self.x + 1, y: self.y , char_map: self.char_map},
|
||||
SymbolPosition{x: self.x - 1, y: self.y + 1, char_map: self.char_map},
|
||||
SymbolPosition{x: self.x , y: self.y + 1, char_map: self.char_map},
|
||||
SymbolPosition{x: self.x + 1, y: self.y + 1, char_map: self.char_map},
|
||||
];
|
||||
|
||||
for neighbour in neighbours{
|
||||
if neighbour.is_digit(){
|
||||
println!("Quack");
|
||||
found_numbers.push(neighbour.find_full_number())
|
||||
}
|
||||
}
|
||||
found_numbers
|
||||
}
|
||||
|
||||
fn is_digit(&self)->bool{
|
||||
let self_char = &*match self.char_map.get(self.y) {
|
||||
None => "".to_string(),
|
||||
Some(char_vec) => match char_vec.get(self.x) {
|
||||
None => "".to_string(),
|
||||
Some(char) => char.to_string()
|
||||
}
|
||||
};
|
||||
|
||||
regex::Regex::new(r"\d")
|
||||
.unwrap()
|
||||
.is_match(self_char)
|
||||
}
|
||||
|
||||
fn find_full_number(self)->i32{
|
||||
// Implement searching for a full number, mainly traverse the
|
||||
// self.y position in the char_map forwards and backwards until
|
||||
// we find the end of the vec, or a non digit character. Preserving
|
||||
// order.
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
fn part_one(contents: &String)-> i32{
|
||||
let mut char_map: Vec<Vec<char>> = Vec::new();
|
||||
let mut symbols: Vec<SymbolPosition> = Vec::new();
|
||||
|
||||
for line in contents.lines(){
|
||||
let line_vec: Vec<char> = line.chars().collect();
|
||||
char_map.push(line_vec);
|
||||
}
|
||||
|
||||
for (y, line) in char_map.iter().enumerate(){
|
||||
for (x, current_char) in line.iter().enumerate(){
|
||||
let non_digit = regex::Regex::new(r"[^\w.]").unwrap();
|
||||
if non_digit.is_match(¤t_char.to_string()){
|
||||
symbols.push(SymbolPosition{x, y , char_map: &char_map})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
symbols[0].explore_neighbours();
|
||||
|
||||
|
||||
|
||||
0
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
mod day1;
|
||||
mod day2;
|
||||
mod day3;
|
||||
|
||||
|
||||
fn main() {
|
||||
day1::run_day1();
|
||||
|
|
|
|||
Loading…
Reference in New Issue