Skip to content

Commit

Permalink
Fix precision issue in day 6
Browse files Browse the repository at this point in the history
  • Loading branch information
timvisee committed Dec 7, 2023
1 parent 5cb657e commit 60035d8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion day06a/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn main() {
)
.map(|(t, d)| {
// Modified quadratic formula: <https://en.wikipedia.org/wiki/Quadratic_formula>
let a = (t - f32::sqrt((t * t - 4 * d) as f32) as usize) / 2;
let a = (t - f64::sqrt((t * t - 4 * d) as f64) as usize) / 2;
let b = t - a;
b - (b * (t - b) <= d) as usize - a - (a * (t - a) <= d) as usize + 1
})
Expand Down
2 changes: 1 addition & 1 deletion day06b/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn main() {
.unwrap();

// Modified quadratic formula: <https://en.wikipedia.org/wiki/Quadratic_formula>
let a = (time - f32::sqrt((time * time - 4 * dist) as f32) as usize) / 2;
let a = (time - f64::sqrt((time * time - 4 * dist) as f64) as usize) / 2;
let b = time - a;
println!(
"{}",
Expand Down

0 comments on commit 60035d8

Please sign in to comment.