/**
 * This function takes a dictionary 'mathDict' representing mathematical equations with keys as indices and values as strings.
 * It also takes an 'index' which specifies the equation to be modified and 'newValue' which is the updated equation.
 * The function updates the equation at the specified index with the new equation and returns the modified mathDict.
 */
fun updateMathDict(mathDict: MutableMap<Int, String>, index: Int, newValue: String): MutableMap<Int, String> {

    if (index in mathDict) {
        mathDict[index] = newValue
    } else {
        val closestIndex = mathDict.keys.minByOrNull { Math.abs(it - index) } ?: 0
        mathDict[closestIndex] = newValue
    }
    return mathDict
}

// Example usage:
/**
 * This function takes a dictionary 'mathDict' representing mathematical equations with keys as indices and values as strings.
 * It also takes an 'index' which specifies the equation to be modified and 'newValue' which is the updated equation.
 * The function updates the equation at the specified index with the new equation and returns the modified mathDict.
 */
fun updateMathDict(mathDict: MutableMap<Int, String>, index: Int, newValue: String): MutableMap<Int, String> {
/**
 * This function takes a dictionary 'mathDict' representing mathematical equations with keys as indices and values as strings.
 * It also takes an 'index' which specifies the equation to be modified and 'newValue' which is the updated equation.
 * The function updates the equation at the specified index with the new equation and returns the modified mathDict.
 */
fun updateMathDict(mathDict: MutableMap<Int, String>, index: Int, newValue: String): MutableMap<Int, String> {

    if (index in mathDict) {
        mathDict[index] = newValue
    } else {
        val closestIndex = mathDict.keys.minByOrNull { Math.abs(it - index) } ?: 0
        mathDict[closestIndex] = newValue
    }
    return mathDict
}

// Example usage: