function run_rules(state) if state["flour"] >= 1 and state["sugar"] >= 1 and state["apples"] >= 1 then emit(state, "apple cake") return run_rules(state) elseif state["apples"] >= 1 and state["oranges"] >= 1 and state["cherries"] >= 1 then emit(state, "fruit salad") return run_rules(state) elseif state["fruit salad"] >= 1 and state["apple cake"] >= 1 then emit(state, "fruit cake") return run_rules(state) else end end tally(state, "sugar") tally(state, "oranges") tally(state, "apples") tally(state, "cherries") tally(state, "flour") tally(state, "apples") run_rules(state)