misc optimizations
This commit is contained in:
7 files changed
+516
-48
No files matched your search
+5
-1
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user