Skip to content

Instantly share code, notes, and snippets.

@isido
Last active August 29, 2015 13:56
Show Gist options
  • Save isido/8863086 to your computer and use it in GitHub Desktop.
Save isido/8863086 to your computer and use it in GitHub Desktop.
var min = [ 1024, 7000, 512];
var max = [ 1024, 1000000, 2048];
var pri = [ 1024, 7000, 512];
var fac = new Array(3);
var free_space = 35000;
for (var i = 0; i < min.length; ++i) {
fac[i] = pri[i] - min[i];
}
var ready = false;
while (!ready) {
var minsum = min[0] + min[1] + min[2];
var facsum = fac[0] + fac[1] + fac[2];
ready = true;
for (var j = 0; i < min.length; ++i) {
var x = min[i] + (free_space - minsum) * fac[i] / facsum;
if (x > max[i]) {
x = max[i];
}
if (x != min[i]) {
ready = false;
min[i] = x;
}
}
}
console.log(min[0], min[1], min[2]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment