/**
 * This exercise requires the chef to create a phrase by concatenating
 * specific elements of a list representing the ingredients.
 * The chef needs to slice the list and concatenate the desired elements
 * to form the final phrase.
 *
 * @param chefName The name of the chef.
 * @param ingredients A list containing the various ingredients.
 * @return The final phrase created by concatenating the desired elements of the list.
 */
fun createPhrase(chefName: String, ingredients: List<String>): String {

    // Extract the desired elements from the list using slicing
    val ingredient1 = ingredients.subList(1, 2).joinToString()
    val ingredient2 = ingredients.subList(ingredients.size - 2, ingredients.size - 1).joinToString()
    val ingredient3 = ingredients.subList(3, ingredients.size).filterIndexed { index, _ -> index % 2 == 0 }.joinToString()
    val ingredient4 = (ingredients.subList(0, 2) + ingredients.subList(ingredients.size - 2, ingredients.size - 1)).joinToString()

    // Concatenate the desired elements to form the final phrase
    var phrase = "$chefName loves to cook with $ingredient1 and $ingredient2"
    phrase += ", but doesn't like $ingredient3 and instead prefers $ingredient4"

    return phrase
}

// Let's test the function
val chefName = "Gordon Ramsay"
/**
 * This exercise requires the chef to create a phrase by concatenating
 * specific elements of a list representing the ingredients.
 * The chef needs to slice the list and concatenate the desired elements
 * to form the final phrase.
 *
 * @param chefName The name of the chef.
 * @param ingredients A list containing the various ingredients.
 * @return The final phrase created by concatenating the desired elements of the list.
 */
fun createPhrase(chefName: String, ingredients: List<String>): String {
/**
 * This exercise requires the chef to create a phrase by concatenating
 * specific elements of a list representing the ingredients.
 * The chef needs to slice the list and concatenate the desired elements
 * to form the final phrase.
 *
 * @param chefName The name of the chef.
 * @param ingredients A list containing the various ingredients.
 * @return The final phrase created by concatenating the desired elements of the list.
 */
fun createPhrase(chefName: String, ingredients: List<String>): String {

    // Extract the desired elements from the list using slicing
    val ingredient1 = ingredients.subList(1, 2).joinToString()
    val ingredient2 = ingredients.subList(ingredients.size - 2, ingredients.size - 1).joinToString()
    val ingredient3 = ingredients.subList(3, ingredients.size).filterIndexed { index, _ -> index % 2 == 0 }.joinToString()
    val ingredient4 = (ingredients.subList(0, 2) + ingredients.subList(ingredients.size - 2, ingredients.size - 1)).joinToString()

    // Concatenate the desired elements to form the final phrase
    var phrase = "$chefName loves to cook with $ingredient1 and $ingredient2"
    phrase += ", but doesn't like $ingredient3 and instead prefers $ingredient4"

    return phrase
}

// Let's test the function
val chefName = "Gordon Ramsay"