/**
 * Given an image represented as a map, replaces all occurrences of the oldColor with the newColor.
 *
 * @param image A map representing an image, where the keys are the coordinates and the values are the colors.
 * @param oldColor The color to be replaced.
 * @param newColor The color to replace the oldColor with.
 * @return The modified image map.
 *
 * Example:
 * val image = mapOf(Pair(0, 0) to "red", Pair(0, 1) to "green", Pair(1, 0) to "red", Pair(1, 1) to "blue")
 * val oldColor = "red"
 * val newColor = "yellow"
 * replaceColor(image, oldColor, newColor) -> mapOf(Pair(0, 0) to "yellow", Pair(0, 1) to "green", Pair(1, 0) to "yellow", Pair(1, 1) to "blue")
 */
fun replaceColor(image: Map<Pair<Int, Int>, String>, oldColor: String, newColor: String): Map<Pair<Int, Int>, String> {

    val modifiedImage = image.toMutableMap()

    for ((coordinate, color) in modifiedImage) {
        if (color == oldColor) {
            modifiedImage[coordinate] = newColor
        }
    }

    return modifiedImage
}
/**
 * Given an image represented as a map, replaces all occurrences of the oldColor with the newColor.
 *
 * @param image A map representing an image, where the keys are the coordinates and the values are the colors.
 * @param oldColor The color to be replaced.
 * @param newColor The color to replace the oldColor with.
 * @return The modified image map.
 *
 * Example:
 * val image = mapOf(Pair(0, 0) to "red", Pair(0, 1) to "green", Pair(1, 0) to "red", Pair(1, 1) to "blue")
 * val oldColor = "red"
 * val newColor = "yellow"
 * replaceColor(image, oldColor, newColor) -> mapOf(Pair(0, 0) to "yellow", Pair(0, 1) to "green", Pair(1, 0) to "yellow", Pair(1, 1) to "blue")
 */
fun replaceColor(image: Map<Pair<Int, Int>, String>, oldColor: String, newColor: String): Map<Pair<Int, Int>, String> {
/**
 * Given an image represented as a map, replaces all occurrences of the oldColor with the newColor.
 *
 * @param image A map representing an image, where the keys are the coordinates and the values are the colors.
 * @param oldColor The color to be replaced.
 * @param newColor The color to replace the oldColor with.
 * @return The modified image map.
 *
 * Example:
 * val image = mapOf(Pair(0, 0) to "red", Pair(0, 1) to "green", Pair(1, 0) to "red", Pair(1, 1) to "blue")
 * val oldColor = "red"
 * val newColor = "yellow"
 * replaceColor(image, oldColor, newColor) -> mapOf(Pair(0, 0) to "yellow", Pair(0, 1) to "green", Pair(1, 0) to "yellow", Pair(1, 1) to "blue")
 */
fun replaceColor(image: Map<Pair<Int, Int>, String>, oldColor: String, newColor: String): Map<Pair<Int, Int>, String> {

    val modifiedImage = image.toMutableMap()

    for ((coordinate, color) in modifiedImage) {
        if (color == oldColor) {
            modifiedImage[coordinate] = newColor
        }
    }

    return modifiedImage
}