misc optimizations

This commit is contained in:
swaits committed 2021-12-07 22:28:46 -07:00
1 parent feca3062c8
commit d1dcb5134a
7 files changed
+516 -48

No files matched your search

+5 -1
View File
@@ -24,7 +24,8 @@ fn compute_fuel(positions: &[isize], target: isize, cheap_fuel: bool) -> usize {
fn find_cheapest_location(positions: &[isize], cheap_fuel: bool) -> usize {
// find start point
let mut position = get_median(positions);
let start = get_median(positions);
let mut position = start;
let mut fuel = compute_fuel(positions, position, cheap_fuel);
// search up
@@ -36,6 +37,9 @@ fn find_cheapest_location(positions: &[isize], cheap_fuel: bool) -> usize {
position += 1;
fuel = new_fuel;
}
if position != start {
return fuel;
}
// search down
loop {