Ohhh.
A brain teaser.
First, no time to run is listed, therefore
I am ignoring build costs.Using the calculations listed earlier in the thread means that the every reactor built is 80% as efficient as the previous one, down to a floor of 10%. Note that this means a 3rd Mk III reactor will never get built in a system as a Mk II is more efficient once the 10% floor is hit. (In a one homeworld game.)
Now, note the conditions you have defined in your opening post mean that this is
not how I would want it handled in game.
In game, energy demand is always going to go up so I would always want the most efficient reactor built and if I've got overhead I don't care, it will get used up soon enough. However, for the conditions of the challenge here is how I would do it, not going to actually code it out but here are the steps (as I see them):
Note (Output of each mark individually) means comparing the value 3 times, once against the output of each mark level of reactor.
1) (Total Demand) / (# of Planets) = (Demand per Planet), simplify the problem to a single planet to start with.
2) Adjust (Demand per Planet) to (Modified Demand per planet) to account for built reactors. Define cost and efficiency of next reactor built for all 3 marks, accounting for reactors already built and number of homeworlds.
3) If (Modified Demand per planet) >= (Output of each mark individually) Then Build (Most Efficient Reactor) and goto Step 2, otherwise skip this step and goto step 4. All reactors built as part of this step 3 get built at every planet.
4) At this point, we can no longer simplify things down to a single planet so accounting for the reactors built in step 3, find (Demand Left for Galaxy).
5) Define cost and efficiency of next reactor built for all 3 marks and then:
6) If (Demand Left for Galaxy) >= (Output of each mark individually) Then Build (Most Efficient Reactor) at planet #1. Repeat at next planet until (Demand Left for Galaxy) < (Output of one of the three marks). Save (Most Efficient Reactor) as (Mark Level Partially Built on X planets.)
ERROR TRAP: If (Demand Left for Galaxy) >= (Output of each mark individually) when (Most Efficient Reactor) has been built at (Max Planets) -1 Then ABORT. Step 3 is wrong.
7) Recalculate (Demand Left For Galaxy).
8.) Calculate build path for reactors spread out over planets.
Special: Check for Mk III only: If (All Planets) have Mk III reactors numbers equal to (Homeworlds) + 1 then Mk III NOT VALID.
Special: Keep track of reactors and if reactor is built on every planet, adjust (Next Reactor Efficiency Built) as appropriate.
8a) Is (Demand Left for Galaxy) < 1x Mk I reactor? If Yes, build 1x Mk I and done.
8b) Is (Demand Left for Galaxy) < 2x Mk I Reactor? If Yes, build 2x Mk I and done.
8c) Is (Demand Left for Galaxy) < 1x Mk II Reactor? If Yes, build 1x Mk II and done.
Can a Mk III still be built somewhere? (Special check under Step 8.) if NO build Mk II, if YES continue below.
8d) Repeat with (Mk II & Mk I), (Mk II & 2x Mk I), (2x Mk II), (2x Mk II & Mk I), build Mk III if you get this far.
9) Recalculate (Demand left for Galaxy) and goto step 8.
When you hit Done in step 8, calculation is finished and you've got the most efficient setup possible.
Also, page 2 get!
D.