  We describe a method to automatically generate an ion implantation recipe, a
set of energies and doses, to produce a desired defect density profile in a
solid using the fewest required energies. We simulate defect density profiles
for a range of ion energies, fit them with an appropriate function, and
interpolate to yield defect density profiles at arbitrary ion energies. Given
$N$ energies, we then optimize a set of $N$ energy-dose pairs to match a given
target defect density profile. Finally, we find the minimum $N$ such that the
error between the target defect density profile and the defect density profile
generated by the $N$ energy-dose pairs is less than a given threshold. Inspired
by quantum sensing applications with nitrogen-vacancy centers in diamond, we
apply our technique to calculate optimal ion implantation recipes to create
uniform-density 1 $\mu$m surface layers of $^{15}$N or vacancies (using
$^4$He).
