diff --git a/src/solutions/day01.rs b/src/solutions/day01.rs index eda372a..32e0245 100644 --- a/src/solutions/day01.rs +++ b/src/solutions/day01.rs @@ -38,7 +38,7 @@ impl Solution for Day01 { &self, input: &mut Vec, ) -> Result, Box> { - const REG: &str = r#"(?=(\d|one|two|three|four|five|six|seven|eight|nine))"#; + const REG: &str = r#"[0-9]|one|two|three|four|five|six|seven|eight|nine"#; let mut total: u32 = 0; for line in input { total += self.regex_get_num(REG, line); @@ -56,9 +56,17 @@ impl Day01 { fn regex_get_num(&self, regex: &str, input: &mut String) -> u32 { let re = Regex::new(regex).unwrap(); + let input = input.replace("oneight", "oneeight"); + let input = input.replace("threeight", "threeeight"); + let input = input.replace("fiveight", "fiveeight"); + let input = input.replace("nineight", "nineeight"); + let input = input.replace("twone", "twoone"); + let input = input.replace("sevenine", "sevennine"); + let input = input.replace("eightwo", "eighttwo"); + // Get all single digits out of string let matches: Vec<&str> = re - .find_iter(input) + .find_iter(&input) .map(|m| m.unwrap().as_str()) .collect();