This commit is contained in:
endernon 2024-12-03 20:18:39 +00:00
parent eab914518a
commit 84bd29b5b4
3 changed files with 19 additions and 34 deletions

View file

@ -15,21 +15,19 @@ fn main() {
println!("{:?}", finalint)
}
fn mul_parse(thelines: Vec<String>, pattern: Regex) -> Vec<String> {
let mut mulvec: Vec<String> = Vec::new();
for i in thelines {
let tempvec: Vec<String> =
pattern.find_iter(&i)
.filter_map(|fr| fr.as_str().parse::<String>().ok()).collect();
let tempvec: Vec<String> = pattern
.find_iter(&i)
.filter_map(|fr| fr.as_str().parse::<String>().ok())
.collect();
for i2 in tempvec {
mulvec.push(i2);
}
}
mulvec
}
fn mul_process(mulvec: Vec<String>, pattern: Regex) -> i64 {
@ -42,7 +40,5 @@ fn mul_process(mulvec: Vec<String>, pattern: Regex) -> i64 {
mulint += (capture1 * capture2) as i64;
}
mulint
}

View file

@ -14,22 +14,20 @@ fn main() {
println!("{finalint}")
}
fn mul_parse(thelines: Vec<String>, pattern: Regex) -> Vec<String> {
let mut mulvec: Vec<String> = Vec::new();
for i in thelines {
let tempvec: Vec<String> =
pattern.find_iter(&i)
.filter_map(|fr| fr.as_str().parse::<String>().ok()).collect();
let tempvec: Vec<String> = pattern
.find_iter(&i)
.filter_map(|fr| fr.as_str().parse::<String>().ok())
.collect();
for i2 in tempvec {
mulvec.push(i2);
}
}
println!("mulvec is {:?}", mulvec);
mulvec
}
fn mul_process(mulvec: Vec<String>, pattern: Regex) -> i64 {
@ -42,12 +40,10 @@ fn mul_process(mulvec: Vec<String>, pattern: Regex) -> i64 {
if let Some(t) = matchdo.find(&i) {
println!("matchdo");
enabled = true;
}
else if let Some(t) = matchdont.find(&i) {
} else if let Some(t) = matchdont.find(&i) {
println!("matchdont");
enabled = false;
}
else if let Some(t) = matchmul.find(&i) {
} else if let Some(t) = matchmul.find(&i) {
if enabled {
println!("matchmul");
let captures = pattern.captures(&i).unwrap();
@ -56,14 +52,7 @@ fn mul_process(mulvec: Vec<String>, pattern: Regex) -> i64 {
mulint += (capture1 * capture2) as i64;
}
}
}
mulint
}

View file

@ -1,3 +1,3 @@
# My solutions for Advent of Code
exactly what the title says, starting 2024, since I feel this would be a great way to learn rust.
exactly what the title says, starting 2024, since I feel this would be a great way to learn rust.cc