day3 progress
This commit is contained in:
54
2023/day3/Cargo.lock
generated
54
2023/day3/Cargo.lock
generated
@@ -2,6 +2,60 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cute"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "45e700c2d1c3feea9b695e79b2dfeeb93040556a58c556fae23f71b1e6b449fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "day3"
|
name = "day3"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"cute",
|
||||||
|
"regex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.10.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.4.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
|
||||||
|
|||||||
@@ -4,3 +4,5 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
cute = "0.3.0"
|
||||||
|
regex = "1.10.6"
|
||||||
|
|||||||
@@ -1,44 +1,39 @@
|
|||||||
use std::{fs::File, io::{self, BufRead}, path::Path, process::exit};
|
use core::num;
|
||||||
#[derive(Debug)]
|
use regex::Regex;
|
||||||
struct Coord{
|
use std::{
|
||||||
line_index: usize,
|
collections::HashMap,
|
||||||
char_index: usize,
|
fs::File,
|
||||||
}
|
io::{self, BufRead},
|
||||||
|
path::Path,
|
||||||
|
process::exit,
|
||||||
|
};
|
||||||
|
#[macro_use(c)]
|
||||||
|
extern crate cute;
|
||||||
fn main() {
|
fn main() {
|
||||||
let symbol_ignore_list = ".123456789";
|
let ignore_list = "01234566789.";
|
||||||
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
|
// File hosts.txt must exist in the current path
|
||||||
if let Ok(lines) = read_lines("./input") {
|
if let Ok(lines) = read_lines("./input") {
|
||||||
// Consumes the iterator, returns an (Optional) String
|
// Consumes the iterator, returns an (Optional) String
|
||||||
let lines_array = lines.flatten().collect::<Vec<String>>();
|
let lines_array: Vec<String> = 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(){
|
let mut symbols: HashMap<(i32, i32), Vec<i32>> = c! {key => Vec::new(), for key in c![(line_index as i32, char_index as i32), for char_index in 0..lines_array[line_index].len(), for line_index in 0..lines_array.len()]};
|
||||||
for char_index in 0..lines_array[line_index].len(){
|
println!("{symbols:?}");
|
||||||
|
exit(0);
|
||||||
|
for (line_index, line) in lines_array.iter().enumerate() {
|
||||||
|
let digit_regex = Regex::new(r"\d+").unwrap();
|
||||||
|
for finding in digit_regex.find_iter(line) {
|
||||||
|
println!("{}", finding.start());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The output is wrapped in a Result to allow matching on errors.
|
// The output is wrapped in a Result to allow matching on errors.
|
||||||
// Returns an Iterator to the Reader of the lines of the file.
|
// Returns an Iterator to the Reader of the lines of the file.result
|
||||||
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
|
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
|
||||||
where P: AsRef<Path>, {
|
where
|
||||||
|
P: AsRef<Path>,
|
||||||
|
{
|
||||||
let file = File::open(filename)?;
|
let file = File::open(filename)?;
|
||||||
Ok(io::BufReader::new(file).lines())
|
Ok(io::BufReader::new(file).lines())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user