Something that compiles at least.
This commit is contained in:
parent
330f90181f
commit
bde96d0efa
@ -43,7 +43,6 @@ struct Policy {
|
|||||||
password: String,
|
password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[aoc_generator(day2)]
|
|
||||||
fn parse_regex<'a>(input: &'a str) -> impl Iterator<Item = Policy> + 'a {
|
fn parse_regex<'a>(input: &'a str) -> impl Iterator<Item = Policy> + 'a {
|
||||||
let re = Regex::new(r"(\d+)-(\d+) (\w): (.*)").expect("Failed to compile regex");
|
let re = Regex::new(r"(\d+)-(\d+) (\w): (.*)").expect("Failed to compile regex");
|
||||||
input
|
input
|
||||||
@ -59,7 +58,6 @@ fn parse_regex<'a>(input: &'a str) -> impl Iterator<Item = Policy> + 'a {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[aoc_generator(day2, part1, handrolled)]
|
|
||||||
fn parse_handrolled<'a>(input: &'a str) -> impl Iterator<Item = Policy> + 'a {
|
fn parse_handrolled<'a>(input: &'a str) -> impl Iterator<Item = Policy> + 'a {
|
||||||
// Example line:
|
// Example line:
|
||||||
// 1-3 a: abcde
|
// 1-3 a: abcde
|
||||||
@ -94,12 +92,14 @@ fn is_valid_policy_part1(p: &Policy) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[aoc(day2, part1)]
|
#[aoc(day2, part1)]
|
||||||
fn valid_policy_count_part1(policies: &mut dyn Iterator<Item = Policy>) -> usize {
|
fn valid_policy_count_part1(input: &str) -> usize {
|
||||||
|
let policies = parse_regex(input);
|
||||||
policies.filter(|p| is_valid_policy_part1(p)).count()
|
policies.filter(|p| is_valid_policy_part1(p)).count()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[aoc(day2, part1, handrolled)]
|
#[aoc(day2, part1, handrolled)]
|
||||||
fn valid_policy_count_handrolled_part1(policies: &mut dyn Iterator<Item = Policy>) -> usize {
|
fn valid_policy_count_handrolled_part1(input: &str) -> usize {
|
||||||
|
let policies = parse_handrolled(input);
|
||||||
policies.filter(|p| is_valid_policy_part1(p)).count()
|
policies.filter(|p| is_valid_policy_part1(p)).count()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +114,8 @@ fn is_valid_policy_part2(p: &Policy) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[aoc(day2, part2)]
|
#[aoc(day2, part2)]
|
||||||
fn valid_policy_count_part2(policies: &mut dyn Iterator<Item = Policy>) -> usize {
|
fn valid_policy_count_part2(input: &str) -> usize {
|
||||||
|
let policies = parse_regex(input);
|
||||||
policies.filter(|p| is_valid_policy_part2(p)).count()
|
policies.filter(|p| is_valid_policy_part2(p)).count()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,11 +156,11 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn validate_count_part1() {
|
fn validate_count_part1() {
|
||||||
assert_eq!(valid_policy_count_part1(&mut parse_regex(INPUT)), 2);
|
assert_eq!(valid_policy_count_part1(INPUT), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn validate_count_part2() {
|
fn validate_count_part2() {
|
||||||
assert_eq!(valid_policy_count_part2(&mut parse_regex(INPUT)), 1);
|
assert_eq!(valid_policy_count_part2(INPUT), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user