local Recipe = require "Recipe" local function raw_materials_needed (quantity) local recipe = Recipe[quantity.material] if not recipe then return {[quantity.material]=quantity.amount} end local total = {} for _, input in pairs(recipe.input) do local subtotal = raw_materials_needed(input) for material, amount in pairs(subtotal) do total[material] = (total[material] or 0) + amount * quantity.amount end end return total end local function pretty_print (acc) for material, amount in pairs(acc) do print(("%d\t%q"):format(amount, material)) end end return { raw_materials_needed=raw_materials_needed, pretty_print=pretty_print, }