aboutsummaryrefslogtreecommitdiff
path: root/src/day1pt1.rs
blob: 643fcd6f54627bf31d5ab0125dffed4c8d700f8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use regex::Regex;

pub fn main() {
    let mut sum: u32 = 0;

    let txt = std::fs::read_to_string("./input/day1.txt").unwrap();
    let re = Regex::new(r"\d").unwrap();

    for line in txt.lines() {
        let capt = re.find_iter(line).collect::<Vec<_>>();
        sum += capt.get(0).unwrap().as_str().parse::<u32>().unwrap() * 10
            + capt
                .get(capt.len() - 1)
                .unwrap()
                .as_str()
                .parse::<u32>()
                .unwrap();
    }

    println!("{}", sum);
}