dychotomy was really unnecessary
This commit is contained in:
parent
e6f0f92251
commit
b307eb91b0
1 changed files with 6 additions and 11 deletions
|
@ -51,17 +51,12 @@ fn solve(puzzle: []const u8, allocator: std.mem.Allocator) !u64 {
|
||||||
}
|
}
|
||||||
try sizes.append(stack.items[n]); // we do not forget the last one
|
try sizes.append(stack.items[n]); // we do not forget the last one
|
||||||
n = 30000000 - (70000000 - tot); // the amount of space we need to free
|
n = 30000000 - (70000000 - tot); // the amount of space we need to free
|
||||||
// let's run a dychotomy on the array
|
// let's find the minimum that is the closest to that
|
||||||
std.sort.sort(u64, sizes.items, {}, std.sort.asc(u64));
|
tot = 70000000;
|
||||||
var a: usize = 0;
|
for (sizes.items) |v| {
|
||||||
var b = sizes.items.len - 1;
|
if (v > n and v < tot) {
|
||||||
while (b - a > 2) {
|
tot = v;
|
||||||
const m = a + (b - a) / 2;
|
|
||||||
if (sizes.items[m] < n) {
|
|
||||||
a = m;
|
|
||||||
} else {
|
|
||||||
b = m;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sizes.items[b];
|
return tot;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue