/**
 * Given two lists of integers representing melodies, this function finds the intersection
 * of the melodies using set comprehension and modulus operator. It returns a new list
 * containing the common elements at the same indices.
 *
 * @param melody1 A list of integers representing the first melody
 * @param melody2 A list of integers representing the second melody
 * @return A new list containing the common elements at the same indices
 *
 * Example:
 * val melody1 = listOf(1, 2, 3, 4, 5)
 * val melody2 = listOf(4, 2, 6, 8, 10)
 * findMelodyIntersection(melody1, melody2) => [2, 4]
 */
fun findMelodyIntersection(melody1: List<Int>, melody2: List<Int>): List<Int> {

    val intersection = melody1.filterIndexed { index, note -> note % melody2[index] == 0 }
    return intersection
}
/**
 * Given two lists of integers representing melodies, this function finds the intersection
 * of the melodies using set comprehension and modulus operator. It returns a new list
 * containing the common elements at the same indices.
 *
 * @param melody1 A list of integers representing the first melody
 * @param melody2 A list of integers representing the second melody
 * @return A new list containing the common elements at the same indices
 *
 * Example:
 * val melody1 = listOf(1, 2, 3, 4, 5)
 * val melody2 = listOf(4, 2, 6, 8, 10)
 * findMelodyIntersection(melody1, melody2) => [2, 4]
 */
fun findMelodyIntersection(melody1: List<Int>, melody2: List<Int>): List<Int> {
/**
 * Given two lists of integers representing melodies, this function finds the intersection
 * of the melodies using set comprehension and modulus operator. It returns a new list
 * containing the common elements at the same indices.
 *
 * @param melody1 A list of integers representing the first melody
 * @param melody2 A list of integers representing the second melody
 * @return A new list containing the common elements at the same indices
 *
 * Example:
 * val melody1 = listOf(1, 2, 3, 4, 5)
 * val melody2 = listOf(4, 2, 6, 8, 10)
 * findMelodyIntersection(melody1, melody2) => [2, 4]
 */
fun findMelodyIntersection(melody1: List<Int>, melody2: List<Int>): List<Int> {

    val intersection = melody1.filterIndexed { index, note -> note % melody2[index] == 0 }
    return intersection
}