How to calculate exploded quantities without recursion