From bde96d0efab1cdbcff54e6aa7ecbe84881587982 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Thu, 3 Dec 2020 19:52:37 -0800 Subject: [PATCH] Something that compiles at least. --- 2020/src/day2.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/2020/src/day2.rs b/2020/src/day2.rs index 10762b8..9cf64ba 100644 --- a/2020/src/day2.rs +++ b/2020/src/day2.rs @@ -43,7 +43,6 @@ struct Policy { password: String, } -#[aoc_generator(day2)] fn parse_regex<'a>(input: &'a str) -> impl Iterator + 'a { let re = Regex::new(r"(\d+)-(\d+) (\w): (.*)").expect("Failed to compile regex"); input @@ -59,7 +58,6 @@ fn parse_regex<'a>(input: &'a str) -> impl Iterator + 'a { }) } -#[aoc_generator(day2, part1, handrolled)] fn parse_handrolled<'a>(input: &'a str) -> impl Iterator + 'a { // Example line: // 1-3 a: abcde @@ -94,12 +92,14 @@ fn is_valid_policy_part1(p: &Policy) -> bool { } #[aoc(day2, part1)] -fn valid_policy_count_part1(policies: &mut dyn Iterator) -> usize { +fn valid_policy_count_part1(input: &str) -> usize { + let policies = parse_regex(input); policies.filter(|p| is_valid_policy_part1(p)).count() } #[aoc(day2, part1, handrolled)] -fn valid_policy_count_handrolled_part1(policies: &mut dyn Iterator) -> usize { +fn valid_policy_count_handrolled_part1(input: &str) -> usize { + let policies = parse_handrolled(input); policies.filter(|p| is_valid_policy_part1(p)).count() } @@ -114,7 +114,8 @@ fn is_valid_policy_part2(p: &Policy) -> bool { } #[aoc(day2, part2)] -fn valid_policy_count_part2(policies: &mut dyn Iterator) -> usize { +fn valid_policy_count_part2(input: &str) -> usize { + let policies = parse_regex(input); policies.filter(|p| is_valid_policy_part2(p)).count() } @@ -155,11 +156,11 @@ mod tests { #[test] fn validate_count_part1() { - assert_eq!(valid_policy_count_part1(&mut parse_regex(INPUT)), 2); + assert_eq!(valid_policy_count_part1(INPUT), 2); } #[test] fn validate_count_part2() { - assert_eq!(valid_policy_count_part2(&mut parse_regex(INPUT)), 1); + assert_eq!(valid_policy_count_part2(INPUT), 1); } }