Canaries, parrots and cats live in the apartment in such a number that only K paws. Derive all possible combinations of the number of canaries, parrots, cats living in the apartment with this total number of paws.
Here's a bit of code that I came up with:
function calculateAnimals(maxPaws) {
if (maxPaws % 2 === 1 || maxPaws === 0) {
console.log("Sorry, not equal amount of paws");
return;
} else if (maxPaws === 8) console.log("Total: 1 canary, 1 parrot, 1 cat");
let maxCanary = maxPaws / 2,
maxParrot = maxPaws / 2,
maxCat = Math.floor(maxPaws / 4);
while (maxCanary !== 0 || maxParrot !== 0 || maxCat !== 0) {
console.log(`Total: ${maxCanary} canary, ${maxParrot} parrot, ${maxCat} cat`);
break;
}
}
console.log(calculateAnimals(20));
As you can see...I'm stuck =) Can't quite figure out how to print all of the possible combinations. I would be incredibly grateful to the person who will help to add/change the code or point me in the right direction for solving this problem