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]
|
||||
nom = "7.1.1"
|
||||
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}");
|
||||
}
|
||||
{
|
||||
let file_path = "prob6_part1.txt";
|
||||
let solution = prob6::solve_part1(file_path);
|
||||
let _file_path = "prob6_part1.txt";
|
||||
let solution = prob6::solve_part1(include_str!("../prob6_part1.txt"));
|
||||
println!("Solution for problem 6 part 1: {solution}");
|
||||
}
|
||||
}
|
||||
|
46
src/prob6.rs
46
src/prob6.rs
@ -1,5 +1,45 @@
|
||||
pub fn solve_part1(file_path: &str) -> i32 {
|
||||
let _content = std::fs::read_to_string(file_path).unwrap_or_else(|err| panic!("{err}"));
|
||||
println!("{_content}");
|
||||
use std::collections::HashSet;
|
||||
|
||||
use fancy_regex::Regex;
|
||||
|
||||
/// 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