Matthew Delaney

Research Scientist ยท Data scientist

Dyson Sphere Program Calculator


Dyson Sphere Program (DSP) is a factory game similar to Factorio, where the player crafts ever more complicated items using previous items as components (Game Wiki: Main page). Calculating the total resources for a given item requires finding all the components of the item, and their sub-components and so on - a perfect use case for some recursive code!

The dsp_calculator.py file is a simple recursive script that when given an item name, it returns all the basic resources and components needed for the full crafting recipe: DSP calculator on Github


An example recipe is shown below, where the final product on the right requires 2 components, each requiring 2 components, totallying 4 "base" inputs. As the items become more advanced these dependencies scale with the power of the number of subcomponents at each level. This can result in very large dependencies which are best handled through recursion instead of using a look up table.

example recipe