1use crate::util::iter::*;
5use crate::util::parse::*;
6
7pub fn parse(input: &str) -> &str {
8 input
9}
10
11pub fn part1(input: &str) -> usize {
12 solve(input, |key, value| match key {
13 "akitas" | "vizslas" => value == 0,
14 "perfumes" => value == 1,
15 "samoyeds" | "cars" => value == 2,
16 "children" | "pomeranians" | "trees" => value == 3,
17 "goldfish" => value == 5,
18 "cats" => value == 7,
19 _ => unreachable!(),
20 })
21}
22
23pub fn part2(input: &str) -> usize {
24 solve(input, |key, value| match key {
25 "akitas" | "vizslas" => value == 0,
26 "perfumes" => value == 1,
27 "samoyeds" | "cars" => value == 2,
28 "children" => value == 3,
29 "pomeranians" => value < 3,
30 "goldfish" => value < 5,
31 "trees" => value > 3,
32 "cats" => value > 7,
33 _ => unreachable!(),
34 })
35}
36
37fn solve(input: &str, predicate: fn(&str, u32) -> bool) -> usize {
38 input
39 .lines()
40 .position(|line| {
41 line.split([' ', ':', ','])
42 .filter(|s| !s.is_empty())
43 .chunk::<2>()
44 .skip(1)
45 .all(|[key, value]| predicate(key, value.unsigned()))
46 })
47 .map(|i| i + 1)
48 .unwrap()
49}