/**
 * Given a dictionary of musicians, perform the following operations:
 *
 * 1. Print the names of all the musicians in the dictionary in reverse order.
 * 2. Print all the musicians whose names start with the letter 'J'.
 * 3. Create a new dictionary with musicians whose ages are greater than or equal to 30.
 * 4. Print the names of the musicians in the new dictionary in alphabetical order.
 * 5. Create a new list with the first 3 musicians from the original dictionary, excluding the last one.
 * 6. Return the total number of musicians in the original dictionary.
 */
fun musicianDictSliceExercise(musicians: Map<String, Int>): Int {

    // 1. Print the names of all the musicians in reverse order.
    val musiciansNames = musicians.keys.toList()
    println(musiciansNames.reversed()) // Reversing the list

    // 2. Print all the musicians whose names start with the letter 'J'.
    println(musiciansNames.filter { it.startsWith("J") }) // Filtering names starting with 'J'

    // 3. Create a new dictionary with musicians whose ages are greater than or equal to 30.
    val musiciansOver30 = musicians.filterValues { it >= 30 }
    
    // 4. Print the names of the musicians in the new dictionary in alphabetical order.
    println(musiciansOver30.keys.sorted()) // Sorting and printing names

    // 5. Create a new list with the first 3 musicians from the original dictionary, excluding the last one.
    val firstThreeMusicians = musiciansNames.take(3).dropLast(1)
    
    // 6. Return the total number of musicians in the original dictionary.
    return musicians.size
}
/**
 * Given a dictionary of musicians, perform the following operations:
 *
 * 1. Print the names of all the musicians in the dictionary in reverse order.
 * 2. Print all the musicians whose names start with the letter 'J'.
 * 3. Create a new dictionary with musicians whose ages are greater than or equal to 30.
 * 4. Print the names of the musicians in the new dictionary in alphabetical order.
 * 5. Create a new list with the first 3 musicians from the original dictionary, excluding the last one.
 * 6. Return the total number of musicians in the original dictionary.
 */
fun musicianDictSliceExercise(musicians: Map<String, Int>): Int {
/**
 * Given a dictionary of musicians, perform the following operations:
 *
 * 1. Print the names of all the musicians in the dictionary in reverse order.
 * 2. Print all the musicians whose names start with the letter 'J'.
 * 3. Create a new dictionary with musicians whose ages are greater than or equal to 30.
 * 4. Print the names of the musicians in the new dictionary in alphabetical order.
 * 5. Create a new list with the first 3 musicians from the original dictionary, excluding the last one.
 * 6. Return the total number of musicians in the original dictionary.
 */
fun musicianDictSliceExercise(musicians: Map<String, Int>): Int {

    // 1. Print the names of all the musicians in reverse order.
    val musiciansNames = musicians.keys.toList()
    println(musiciansNames.reversed()) // Reversing the list

    // 2. Print all the musicians whose names start with the letter 'J'.
    println(musiciansNames.filter { it.startsWith("J") }) // Filtering names starting with 'J'

    // 3. Create a new dictionary with musicians whose ages are greater than or equal to 30.
    val musiciansOver30 = musicians.filterValues { it >= 30 }
    
    // 4. Print the names of the musicians in the new dictionary in alphabetical order.
    println(musiciansOver30.keys.sorted()) // Sorting and printing names

    // 5. Create a new list with the first 3 musicians from the original dictionary, excluding the last one.
    val firstThreeMusicians = musiciansNames.take(3).dropLast(1)
    
    // 6. Return the total number of musicians in the original dictionary.
    return musicians.size
}