25/42
Part 6 of 8 · The best setLearn and do
You may stop at the first size that fits only when the fewest machines come first
With fewest machines first, the first size that has any set with 8 GPUs holds the winner. You can stop there: size 1 already has atlas.
With least cost first, you can't. Here is the cheapest set that fits at each size:
| Size | Cheapest set with 8 GPUs | Cost |
|---|---|---|
| 1 | atlas | 20 |
| 2 | birch, cedar | 17 |
| 3 | cedar, delta, ember | 16 |
| 4 | birch, cedar, delta, ember | 25 |
A search that stops at the first size with a fit returns atlas, for 20. The best set has 3 machines and costs 16. A set is ranked by its key, not by when the loop met it.
In the editor, write the loop body of cheapest_set(machines, need): for each set that fits, build its key, the least cost, then the fewest machines, then the names, and keep the smallest in best.