pub fn execute_task01(content: &str) {
    let calibration = solve_01(content);

    assert_eq!(calibration, 56465);
    println!("Day01 - Task01 - Calibration: {}", calibration)
}

pub fn execute_task02(content: &str) {
    let calibration = solve_02(content);

    assert_eq!(calibration, 55902);
    println!("Day01 - Task02 - Calibration: {}", calibration)
}

pub fn solve_01(data: &str) -> i32 {
    let iter = data.lines()
        .map(|line| line.to_string());
    sum_lines(iter)
}

pub fn solve_02(data: &str) -> i32 {
    let iter = data.lines()
        .map(|line| {
            line.replace("one", "o1e")
                .replace("two", "t2o")
                .replace("three", "t3e")
                .replace("four", "f4r")
                .replace("five", "f5e")
                .replace("six", "s6x")
                .replace("seven", "s7n")
                .replace("eight", "e8t")
                .replace("nine", "n9e")
        });

    sum_lines(iter)
}

fn sum_lines(iter: impl Iterator<Item=String>) -> i32 {
    iter
    .map(|line| format!("{}{}",
                        line.matches(|c: char| c.is_ascii_digit()).next().unwrap(),
                        line.rmatches(|c: char| c.is_ascii_digit()).next().unwrap()))
    .map(|number_str| number_str.parse::<i32>().unwrap())
    .sum()
}

#[test]
fn test_solve_01() {
    let test_input = r#"1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet"#;

    let solution = solve_01(test_input);

    assert_eq!(142, solution);
}

#[test]
fn test_solve_02() {
    let test_input = r#"two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen"#;

    let solution = solve_02(test_input);

    assert_eq!(281, solution);
}