Calculate filament cost per gram—then keep going

Calculate filament cost per gram and material cost for a 3D print, including supports, purge waste, spool weight, and failed-print allowance.