Skip to content

Commit 1628551

Browse files
committed
refactor(13/2024): extract parse method
1 parent 03b46f8 commit 1628551

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/solutions/year2024/day13.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ pub struct Day13;
77

88
impl Solution for Day13 {
99
fn part_one(&self, input: &str) -> String {
10-
input
11-
.split_terminator("\n\n")
12-
.map(|s| s.parse::<Machine>().unwrap())
10+
self.parse(input)
11+
.iter()
1312
.filter_map(|machine| {
1413
machine
1514
.solve_2x2_system()
@@ -20,9 +19,8 @@ impl Solution for Day13 {
2019
}
2120

2221
fn part_two(&self, input: &str) -> String {
23-
input
24-
.split_terminator("\n\n")
25-
.map(|s| s.parse::<Machine>().unwrap())
22+
self.parse(input)
23+
.iter()
2624
.filter_map(|machine| {
2725
machine
2826
.move_prize_by_10000000000000()
@@ -34,6 +32,15 @@ impl Solution for Day13 {
3432
}
3533
}
3634

35+
impl Day13 {
36+
fn parse(&self, input: &str) -> Vec<Machine> {
37+
input
38+
.split_terminator("\n\n")
39+
.map(|s| s.parse::<Machine>().unwrap())
40+
.collect()
41+
}
42+
}
43+
3744
#[derive(Debug)]
3845
struct Machine {
3946
a: Point,

0 commit comments

Comments
 (0)