Skip to content

Commit f3a49fd

Browse files
committed
Refactor day 13 just a bit
1 parent 7f18cf0 commit f3a49fd

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

aoc-solver/src/y2024/day13.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,12 @@ fn parse(input: &str) -> Result<Vec<Machine>, AocError> {
5757
}
5858

5959
fn find_fewest_tokens(
60-
Machine { price, a, b }: &Machine,
61-
unit_conversion_error: bool,
60+
Machine { mut price, a, b }: &Machine,
61+
fix_unit_conversion_error: bool,
6262
) -> Option<i64> {
63-
let price = if !unit_conversion_error {
64-
(price.0 + 10000000000000, price.1 + 10000000000000)
65-
} else {
66-
*price
67-
};
63+
if fix_unit_conversion_error {
64+
price = (price.0 + 10000000000000, price.1 + 10000000000000)
65+
}
6866

6967
// Solving `a_presses` and `b_presses`
7068
// from a system of two equations, accepting only integer solutions:
@@ -97,7 +95,7 @@ impl Solution for Day13 {
9795

9896
let fewest = machines
9997
.iter()
100-
.filter_map(|machine| find_fewest_tokens(machine, true))
98+
.filter_map(|machine| find_fewest_tokens(machine, false))
10199
.sum();
102100

103101
Ok(fewest)
@@ -108,7 +106,7 @@ impl Solution for Day13 {
108106

109107
let fewest = machines
110108
.iter()
111-
.filter_map(|machine| find_fewest_tokens(machine, false))
109+
.filter_map(|machine| find_fewest_tokens(machine, true))
112110
.sum();
113111

114112
Ok(fewest)

0 commit comments

Comments
 (0)