1
0

End of day commit

This commit is contained in:
Florent DENEF 2022-12-28 16:53:51 +01:00
parent 63a4047c30
commit 9a050b663d

View File

@ -17,7 +17,7 @@ use fancy_regex::Regex;
/// ``` /// ```
fn begin_datagram(datagram: &str) { fn begin_datagram(datagram: &str) {
let mut letters = HashSet::<char>::new(); let mut letters = HashSet::<char>::new();
let mut primary_iter = datagram.chars().fuse(); let primary_iter = datagram.chars().fuse();
let mut motif_iter = primary_iter.clone(); let mut motif_iter = primary_iter.clone();
while letters.len() < 4 { while letters.len() < 4 {
if let Some(tmp) = motif_iter.next() { if let Some(tmp) = motif_iter.next() {
@ -32,9 +32,21 @@ fn begin_datagram(datagram: &str) {
pub fn solve_part1(content: &str) -> i32 { pub fn solve_part1(content: &str) -> i32 {
let _content = content; let _content = content;
return match Regex::new(r"^.*(.).*\1.*$") { return match Regex::new(r"^(?:([A-Za-z])(?!.*\1))*$") {
Ok(_reg) => { Ok(_reg) => {
println!("Regex is built."); 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 0
} }
Err(err) => { Err(err) => {