Using regex but will try to solve the problem without it.,
This commit is contained in:
parent
9c1a7818b2
commit
63a4047c30
@ -13,3 +13,4 @@ rpath = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
nom = "7.1.1"
|
nom = "7.1.1"
|
||||||
itertools = "0.10.5"
|
itertools = "0.10.5"
|
||||||
|
fancy-regex = { version = "0.10.0", features = ["perf-literal", "perf-dfa", "perf-inline", "perf-cache"] }
|
||||||
|
@ -44,8 +44,8 @@ fn main() {
|
|||||||
println!("Solution for problem 5 part 2: {max_part1}");
|
println!("Solution for problem 5 part 2: {max_part1}");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let file_path = "prob6_part1.txt";
|
let _file_path = "prob6_part1.txt";
|
||||||
let solution = prob6::solve_part1(file_path);
|
let solution = prob6::solve_part1(include_str!("../prob6_part1.txt"));
|
||||||
println!("Solution for problem 6 part 1: {solution}");
|
println!("Solution for problem 6 part 1: {solution}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
48
src/prob6.rs
48
src/prob6.rs
@ -1,5 +1,45 @@
|
|||||||
pub fn solve_part1(file_path: &str) -> i32 {
|
use std::collections::HashSet;
|
||||||
let _content = std::fs::read_to_string(file_path).unwrap_or_else(|err| panic!("{err}"));
|
|
||||||
println!("{_content}");
|
use fancy_regex::Regex;
|
||||||
0
|
|
||||||
|
/// Tries to find the 4 character match.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `datagram`:
|
||||||
|
///
|
||||||
|
/// returns: ()
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
fn begin_datagram(datagram: &str) {
|
||||||
|
let mut letters = HashSet::<char>::new();
|
||||||
|
let mut primary_iter = datagram.chars().fuse();
|
||||||
|
let mut motif_iter = primary_iter.clone();
|
||||||
|
while letters.len() < 4 {
|
||||||
|
if let Some(tmp) = motif_iter.next() {
|
||||||
|
if !letters.insert(tmp) {
|
||||||
|
letters.clear();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn solve_part1(content: &str) -> i32 {
|
||||||
|
let _content = content;
|
||||||
|
return match Regex::new(r"^.*(.).*\1.*$") {
|
||||||
|
Ok(_reg) => {
|
||||||
|
println!("Regex is built.");
|
||||||
|
0
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("{err}");
|
||||||
|
0
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user