  Adaptable, low-cost, coils designed by carefully selecting the arrangements
and geometries of simple primitive units are used to generate magnetic fields
for diverse applications. These extend from magnetic resonance and fundamental
physics experiments to active shielding of quantum devices including
magnetometers, interferometers, clocks, and computers. However, finding optimal
arrangements and geometries of multiple primitive structures is time-intensive
and it is challenging to account for additional constraints, e.g. optical
access, during the design process. Here, we demonstrate a general method to
find these optimal arrangements. We encode specific symmetries into sets of
loops, saddles, and cylindrical ellipses and then solve exactly for the
magnetic field harmonics generated by each set. By combining these analytic
solutions using computer algebra, we can use numerical techniques to
efficiently map the landscape of parameters and geometries which the coils must
satisfy. Sets of solutions may be found which generate desired target fields
accurately while accounting for complexity and size restrictions. We
demonstrate this approach by employing simple configurations of loops, saddles,
and cylindrical ellipses to design target linear field gradients and compare
their performance with designs obtained using conventional methods. A case
study is presented where three optimized arrangements of loops, designed to
generate a uniform axial field, a linear axial field gradient, and a quadratic
axial field gradient, respectively, are hand-wound around a low-cost,
3D-printed coil former. These coils are used to null the background in a
typical laboratory environment, reducing the magnitude of the axial field along
the central half of the former's axis from $\left(7.8\pm0.3\right)$ $\mu$T
(mean $\pm$ st. dev.) to $\left(0.11\pm0.04\right)$ $\mu$T.
