diff --git a/2024/day3/part1/src/main.rs b/2024/day3/part1/src/main.rs index 8b04ac0..35510ff 100644 --- a/2024/day3/part1/src/main.rs +++ b/2024/day3/part1/src/main.rs @@ -11,25 +11,23 @@ fn main() { let pattern2 = Regex::new(r"mul\((\d+)\,(\d+)\)").unwrap(); let mut finalvec1 = mul_parse(lines, pattern1); - let finalint = mul_process(finalvec1,pattern2); - println!("{:?}",finalint) + let finalint = mul_process(finalvec1, pattern2); + println!("{:?}", finalint) } - -fn mul_parse(thelines: Vec, pattern: Regex) -> Vec{ +fn mul_parse(thelines: Vec, pattern: Regex) -> Vec { let mut mulvec: Vec = Vec::new(); for i in thelines { - let tempvec: Vec = - pattern.find_iter(&i) - .filter_map(|fr| fr.as_str().parse::().ok()).collect(); + let tempvec: Vec = pattern + .find_iter(&i) + .filter_map(|fr| fr.as_str().parse::().ok()) + .collect(); for i2 in tempvec { mulvec.push(i2); } - } mulvec - } fn mul_process(mulvec: Vec, pattern: Regex) -> i64 { @@ -42,7 +40,5 @@ fn mul_process(mulvec: Vec, pattern: Regex) -> i64 { mulint += (capture1 * capture2) as i64; } - mulint - -} \ No newline at end of file +} diff --git a/2024/day3/part2/src/main.rs b/2024/day3/part2/src/main.rs index 622af99..47f1e5d 100644 --- a/2024/day3/part2/src/main.rs +++ b/2024/day3/part2/src/main.rs @@ -9,27 +9,25 @@ fn main() { .collect(); let pattern1 = Regex::new(r"(mul\((\d+)\,(\d+)\))|(do\(\))|(don\'t\(\))").unwrap(); let finalvec1 = mul_parse(lines, pattern1.clone()); - let finalint = mul_process(finalvec1,pattern1.clone()); + let finalint = mul_process(finalvec1, pattern1.clone()); // println!("{:?}",finalint) println!("{finalint}") } - -fn mul_parse(thelines: Vec, pattern: Regex) -> Vec{ +fn mul_parse(thelines: Vec, pattern: Regex) -> Vec { let mut mulvec: Vec = Vec::new(); for i in thelines { - let tempvec: Vec = - pattern.find_iter(&i) - .filter_map(|fr| fr.as_str().parse::().ok()).collect(); + let tempvec: Vec = pattern + .find_iter(&i) + .filter_map(|fr| fr.as_str().parse::().ok()) + .collect(); for i2 in tempvec { mulvec.push(i2); } - } - println!("mulvec is {:?}",mulvec); + println!("mulvec is {:?}", mulvec); mulvec - } fn mul_process(mulvec: Vec, pattern: Regex) -> i64 { @@ -42,12 +40,10 @@ fn mul_process(mulvec: Vec, 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, pattern: Regex) -> i64 { mulint += (capture1 * capture2) as i64; } } - - - - - } - mulint - -} \ No newline at end of file +} diff --git a/readme.md b/readme.md index c2904ae..21e3fd2 100644 --- a/readme.md +++ b/readme.md @@ -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. \ No newline at end of file +exactly what the title says, starting 2024, since I feel this would be a great way to learn rust.cc \ No newline at end of file