Created
March 1, 2020 20:39
-
-
Save mareksip/be248d7f827740d466c517bb34f5d37c to your computer and use it in GitHub Desktop.
apple-distribution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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