fn main() {
    let input = include_str!("./input.txt");
    let output = process(input);
    println!("{}", output);
}

fn process(input: &str) -> i32 {
    let lines: i32 = input
        .lines()
        .map(|line| {
            let line_vec = line
                .chars()
                .filter(|c| c.is_ascii_digit())
                .collect::<Vec<char>>();
            let first = line_vec.clone().into_iter().next();
            let last = line_vec.clone().into_iter().nth_back(0);
            [first.unwrap(), last.unwrap()].into_iter().collect()
        })
        .collect::<Vec<String>>()
        .iter()
        .map(|x| x.parse::<i32>().unwrap())
        .sum();
    lines
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_logic() {
        let input = include_str!("./testinput.txt");
        assert_eq!(process(input), 142);
    }
}
