Created
November 28, 2018 19:17
-
-
Save stephenmathieson/c3d4cd77f6c6e55ab312224e0dac8f01 to your computer and use it in GitHub Desktop.
Revisions
-
stephenmathieson created this gist
Nov 28, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ function fillBucket(remainingWeight, piles, n) { if (n === 0 || remainingWeight === 0) { return 0; } const pile = piles[n - 1]; if (pile.weight > remainingWeight) { return fillBucket(remainingWeight, piles, n - 1); } return Math.max( pile.count + fillBucket(remainingWeight - pile.weight, piles, n - 1), fillBucket(remainingWeight, piles, n - 1) ); } const maxWeight = 50; const piles = [ { count: 60, weight: 10 }, { count: 120, weight: 30 }, { count: 100, weight: 20 } ]; console.log(fillBucket(maxWeight, piles, piles.length));