27/42
Part 6 of 8 · The best setLearn and do
Trying every set is O(n 2^n): fine for about 15 items, out of reach for thousands
Each set costs O(n) to add up, so trying every set is O(n 2^n). Here it is timed with your cheapest_set search. The machines are random, with 1 to 8 GPUs each, and the need is twice the number of machines:
| Machines | Sets | Time to try them all |
|---|---|---|
| 10 | 1,023 | 1.0 ms |
| 15 | 32,767 | 29.9 ms |
| 20 | 1,048,575 | 1,193.6 ms |
For the 15 or so machines in one rack, or listings in one neighborhood, that's fine, and it's the right first answer.
Every 5 more items multiply the number of sets by 32. Thirty machines have 1,073,741,823 sets. At the rate measured for 20, about 880,000 sets a second, that's about 20 minutes. Thousands are out of reach for any computer.
In the editor, write sets(n), how many sets of n items aren't empty, and minutes(n, per_second), how long trying them all takes at that many sets a second.