0

I have a list of 15-20 conservation sites each with an attached cost. I have a budget of £500,000. How do I find all combinations of sites which are under budget?

I was thinking of making a set of objects with a name and cost but I don't know where to begin otherwise:

const sites = [{Clattinger, 47.92},{Clifton, 97.36},{Cricklade, 35.29},{Ducklington, 8.9},{EastCottingwith, 80.43},{Elmlea, 11.13},{Fancott, 3.18},{Lugg, 201.87},{Millcrook, 4.53},{Mottey, 35.45},{Oxley, 6.2},{Pixey, 25.59},{Portholme, 82.65},{Upham, 168.49},{Upton, 89.97},{Westsedgemoor, 363.99},{Wheldrake, 29.33},{Woodside, 1.35},{Yarnton, 68.03}];
MHz
  • 358
  • 1
  • 2
  • 10
  • You can use array. And use array filter method according to the budget. – Bimal Pariyar Dec 19 '21 at 09:50
  • I think you need another approach, the number of all the combinatons of 20 is 20!, you're running out of memory before they're calculated. See https://stackoverflow.com/q/9960908/1169519 – Teemu Dec 19 '21 at 09:53
  • So to reduce the number I would filter combinations based on if they are close to the budget before storing them in the super set. – MHz Dec 19 '21 at 10:03
  • @BimalPariyar I don't think a simple filter will work because I have to sum the costs of the combinations which will be different if I select A+B+C and A+C+D. Unless I don't know its advanced features. – MHz Dec 19 '21 at 10:14

0 Answers0