1
0

Day - part 1 done hehehe

This commit is contained in:
Florent DENEF 2022-12-29 13:55:39 +01:00
parent 9a050b663d
commit 6a8ea1b392
2 changed files with 8 additions and 53 deletions

View File

@ -13,4 +13,3 @@ 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"] }

View File

@ -1,57 +1,13 @@
use std::collections::HashSet;
use itertools::Itertools;
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 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;
}
}
fn begin_datagram(datagram: &str, size: usize) -> usize {
size + datagram
.as_bytes()
.windows(size)
.position(|window| window.iter().tuple_combinations().all(|(a, b)| a != b))
.unwrap()
}
pub fn solve_part1(content: &str) -> i32 {
let _content = content;
return match Regex::new(r"^(?:([A-Za-z])(?!.*\1))*$") {
Ok(_reg) => {
println!("Regex is built.");
match _reg.find(_content) {
Ok(matches) => {
if let Some(yay) = matches {
println!("{}", yay.as_str());
} else {
println!("Snif no match :(");
}
}
Err(err) => {
eprintln!("{err}")
}
}
0
}
Err(err) => {
eprintln!("{err}");
0
}
};
begin_datagram(content, 4) as i32
}