Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kcaffrey committed Dec 6, 2023
1 parent c509425 commit 8752b60
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/bin/06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,15 @@ impl Race {
//
let rt = self.time as f64;
let bd = self.best_distance as f64;
let mut lower_bound = (0.5 * (rt - (rt * rt - 4. * bd).sqrt())).ceil().max(0.) as u64;
let mut upper_bound = (0.5 * (rt + (rt * rt - 4. * bd).sqrt())).floor().min(rt) as u64;
if self.calculate_distance(lower_bound) <= self.best_distance {
lower_bound += 1;
}
if self.calculate_distance(upper_bound) <= self.best_distance {
upper_bound -= 1;
}
let lower_bound = (0.5 * (rt - (rt * rt - 4. * bd).sqrt())).max(0.);
let upper_bound = (0.5 * (rt + (rt * rt - 4. * bd).sqrt())).min(rt);
let lower_bound = (lower_bound + 1.).floor() as u64;
let upper_bound = (upper_bound - 1.).ceil() as u64;
if upper_bound < lower_bound {
return 0;
}
upper_bound - lower_bound + 1
}

pub fn calculate_distance(self, charge_time: u64) -> u64 {
// See above
charge_time * (self.time - charge_time)
}
}

#[derive(Debug)]
Expand Down

0 comments on commit 8752b60

Please sign in to comment.