init day3
This commit is contained in:
44
2023/day3/src/main.rs
Normal file
44
2023/day3/src/main.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
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())
|
||||
}
|
||||
Reference in New Issue
Block a user