/**
 * This exercise is about a chef named chefName who is trying to cook a dish using a list of ingredients.
 * However, the chef is stuck in an infinite while loop and needs your help to fix it.
 *
 * Your task is to loop through the list of ingredients and cook each ingredient until all ingredients are cooked.
 * Once all the ingredients are cooked, the loop should terminate.
 *
 * Hint: To cook an ingredient, decrement its cooking time by 1 each time the loop runs. If the cooking time
 * becomes 0, remove the ingredient from the list.
 *
 * Complete the code below to solve the exercise.
 */
fun cook(chefName: String, ingredients: MutableList<MutableMap<String, Int>>): String {

    while (true) {
        val iterator = ingredients.iterator()
        while (iterator.hasNext()) {
            val ingredient = iterator.next()
            // Cook the ingredient by decrementing its cooking time
            ingredient["cooking_time"] = ingredient["cooking_time"]!! - 1

            // Check if the ingredient has finished cooking
            if (ingredient["cooking_time"] == 0) {
                // Remove the cooked ingredient from the list
                iterator.remove()
            }
        }

        // Check if all ingredients are cooked
        if (ingredients.isEmpty()) {
            break
        }
    }

    return "$chefName has finished cooking all the ingredients!"
}

// Example
/**
 * This exercise is about a chef named chefName who is trying to cook a dish using a list of ingredients.
 * However, the chef is stuck in an infinite while loop and needs your help to fix it.
 *
 * Your task is to loop through the list of ingredients and cook each ingredient until all ingredients are cooked.
 * Once all the ingredients are cooked, the loop should terminate.
 *
 * Hint: To cook an ingredient, decrement its cooking time by 1 each time the loop runs. If the cooking time
 * becomes 0, remove the ingredient from the list.
 *
 * Complete the code below to solve the exercise.
 */
fun cook(chefName: String, ingredients: MutableList<MutableMap<String, Int>>): String {
/**
 * This exercise is about a chef named chefName who is trying to cook a dish using a list of ingredients.
 * However, the chef is stuck in an infinite while loop and needs your help to fix it.
 *
 * Your task is to loop through the list of ingredients and cook each ingredient until all ingredients are cooked.
 * Once all the ingredients are cooked, the loop should terminate.
 *
 * Hint: To cook an ingredient, decrement its cooking time by 1 each time the loop runs. If the cooking time
 * becomes 0, remove the ingredient from the list.
 *
 * Complete the code below to solve the exercise.
 */
fun cook(chefName: String, ingredients: MutableList<MutableMap<String, Int>>): String {

    while (true) {
        val iterator = ingredients.iterator()
        while (iterator.hasNext()) {
            val ingredient = iterator.next()
            // Cook the ingredient by decrementing its cooking time
            ingredient["cooking_time"] = ingredient["cooking_time"]!! - 1

            // Check if the ingredient has finished cooking
            if (ingredient["cooking_time"] == 0) {
                // Remove the cooked ingredient from the list
                iterator.remove()
            }
        }

        // Check if all ingredients are cooked
        if (ingredients.isEmpty()) {
            break
        }
    }

    return "$chefName has finished cooking all the ingredients!"
}

// Example