We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5c0fc8c commit 47b39bfCopy full SHA for 47b39bf
src/year2019/day14.rs
@@ -79,16 +79,15 @@ pub fn part1(input: &[Reaction]) -> u64 {
79
/// Find the maximum amount of fuel possible from 1 trillion ore with an efficient binary search.
80
pub fn part2(input: &[Reaction]) -> u64 {
81
let threshold = 1_000_000_000_000;
82
- let mut start = 1;
+ let mut start = 1_u64;
83
let mut end = threshold;
84
85
- while start < end {
86
- let middle = (start + end) / 2;
+ while start != end {
+ let middle = (start + end).div_ceil(2);
87
88
match ore(input, middle).cmp(&threshold) {
89
- Ordering::Less => start = middle + 1,
90
- Ordering::Equal => return middle,
91
Ordering::Greater => end = middle - 1,
+ _ => start = middle,
92
}
93
94
0 commit comments