Skip to content

Commit 21bc880

Browse files
committed
Minor style
1 parent d3b0631 commit 21bc880

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

aoc2024/src/bin/19.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ use itertools::Itertools;
55

66
advent_of_code::solution!(19);
77

8+
fn parse_input(input: &str) -> (Vec<&str>, HashSet<&str>, usize) {
9+
let blocks = input.blocks();
10+
let towels = blocks[0].split(", ").collect::<HashSet<&str>>();
11+
let max_len = towels
12+
.iter()
13+
.map(|s| s.len())
14+
.max()
15+
.expect("There should be a max");
16+
let patterns = blocks[1].lines().collect_vec();
17+
(patterns, towels, max_len)
18+
}
19+
820
fn is_possible<'a>(
921
s: &'a str,
1022
towels: &HashSet<&'a str>,
@@ -35,19 +47,11 @@ fn is_possible<'a>(
3547
}
3648

3749
pub fn part_one(input: &str) -> Option<u64> {
38-
let blocks = input.blocks();
39-
let towels = blocks[0].split(", ").collect::<HashSet<&str>>();
40-
let max_len = towels
41-
.iter()
42-
.map(|s| s.len())
43-
.max()
44-
.expect("There should be a max");
45-
let patterns = blocks[1].lines().collect_vec();
46-
let mut memo = HashMap::new();
50+
let (patterns, towels, max_len) = parse_input(input);
4751
Some(
4852
patterns
4953
.into_iter()
50-
.filter(|s| is_possible(s, &towels, max_len, &mut memo))
54+
.filter(|s| is_possible(s, &towels, max_len, &mut HashMap::new()))
5155
.count() as u64,
5256
)
5357
}
@@ -77,19 +81,11 @@ fn possible_ways<'a>(
7781
}
7882

7983
pub fn part_two(input: &str) -> Option<u64> {
80-
let blocks = input.blocks();
81-
let towels = blocks[0].split(", ").collect::<HashSet<&str>>();
82-
let max_len = towels
83-
.iter()
84-
.map(|s| s.len())
85-
.max()
86-
.expect("There should be a max");
87-
let patterns = blocks[1].lines().collect_vec();
88-
let mut memo = HashMap::new();
84+
let (patterns, towels, max_len) = parse_input(input);
8985
Some(
9086
patterns
9187
.into_iter()
92-
.map(|s| possible_ways(s, &towels, max_len, &mut memo))
88+
.map(|s| possible_ways(s, &towels, max_len, &mut HashMap::new()))
9389
.sum::<u64>(),
9490
)
9591
}

0 commit comments

Comments
 (0)