var p72 = {count: 72};
var p84 = {count: 84};
var p90 = {count: 90};
var items = [p72, p84, p90];
var count = 1043;
var minVal = Infinity;
var solutions = [];
var val;
for (var i = 0, item = items[i]; i < items.length; item = items[++i]) item.max = Math.ceil(count / item.count);
for (p72.i = 0; p72.i <= p72.max; p72.i += 1)
for (p84.i = 0; p84.i <= p84.max; p84.i += 1)
for (p90.i = 0; p90.i <= p90.max; p90.i += 1) {
val = p90.i * p90.count + p84.i * p84.count + p72.i * p72.count;
if (val < count) continue;
if (val < minVal) {
solutions = [];
solutions.count = val;
minVal = val;
}
if (val === minVal) solutions.push([p72.i, p84.i, p90.i]);
}
console.log(solutions); // 1044 9 вариатнов
#!/usr/bin/env python
rack_s=0 #72
rack_m=0 #84
rack_b=0 #90
min_b=0
min_m=0
min_s=0
empty=1000
for blocks in range(70,100):
empty=blocks
for rack_b in range(0,100):
for rack_m in range(0,100):
for rack_s in range (0,100):
space=rack_s * 72 + rack_m * 84 + rack_b * 90
if space >= blocks:
if empty > (space - blocks):
empty=space - blocks
min_b=rack_b
min_m=rack_m
min_s=rack_s
break
print ("Blocks:", blocks, " Empty blocks :",empty, " Racks: Big, Medium, Small:", min_b, min_m, min_s)