Skip to content

Instantly share code, notes, and snippets.

@mareksip
Created March 1, 2020 20:39
Show Gist options
  • Save mareksip/be248d7f827740d466c517bb34f5d37c to your computer and use it in GitHub Desktop.
Save mareksip/be248d7f827740d466c517bb34f5d37c to your computer and use it in GitHub Desktop.
apple-distribution
function applesDistribution(apples, boxCapacity, maxResidue) {
var distributionCount = 0;
for(var i = 1; i < apples; i++){
console.log("i " + i);
if(apples % i == 0){
distributionCount++;
console.log("match!");
} else {
for(var j = 1; j <= maxResidue; j++){
var boxCapacity = (apples - j) / i;
console.log("boxCapacity: " + boxCapacity);
if(boxCapacity < 1){
distributionCount++;
console.log("match!");
continue;
}
if(boxCapacity % 1 != 0) {
continue;
}
var leftOut = apples - (boxCapacity * i);
console.log("leftout " + leftOut);
if(leftOut < boxCapacity){
distributionCount++;
console.log("match!");
}
}
}
}
return distributionCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment