Files
adventofcode/2023/day3/src/main.rs
2024-09-22 22:10:06 +02:00

44 lines
1.7 KiB
Rust

use std::{fs::File, io::{self, BufRead}, path::Path, process::exit};
#[derive(Debug)]
struct Coord{
line_index: usize,
char_index: usize,
}
fn main() {
let symbol_ignore_list = ".123456789";
let mut result = 0;
// symbol_array is a list of a list of coords.
// each list this array represents a line
// inside the line is the list of the coords of each symbol
let mut symbol_array: Vec<Vec<Coord>> = Vec::new();
// File hosts.txt must exist in the current path
if let Ok(lines) = read_lines("./input") {
// Consumes the iterator, returns an (Optional) String
let lines_array = lines.flatten().collect::<Vec<String>>();
// collect a list of all symbols
for line_index in 0..lines_array.len(){
let mut line_symbol_array: Vec<Coord> = Vec::new();
for char_index in 0..lines_array[line_index].len(){
let cur_char = lines_array[line_index].chars().collect::<Vec<char>>()[char_index];
if !symbol_ignore_list.contains(cur_char){
let c = Coord{line_index:line_index,char_index:char_index};
line_symbol_array.push(c);
}
}
symbol_array.push(line_symbol_array);
}
for line_index in 0..lines_array.len(){
for char_index in 0..lines_array[line_index].len(){
}
}
}
// The output is wrapped in a Result to allow matching on errors.
// Returns an Iterator to the Reader of the lines of the file.
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
where P: AsRef<Path>, {
let file = File::open(filename)?;
Ok(io::BufReader::new(file).lines())
}