/**
 * This function calculates the total tax to be paid based on the given income and tax brackets.
 *
 * @param income The total income of the person.
 * @param taxBrackets A list of pairs representing the tax brackets and corresponding tax rates.
 * @return The total tax amount to be paid.
 */
fun calculateTax(income: Double, taxBrackets: List<Pair<Double, Double>>): Double {

    var totalTax = 0.0
    var currentIncome = income

    while (currentIncome > 0) {
        for (bracket in taxBrackets) {
            if (currentIncome > bracket.first) {
                val taxableAmount = minOf(currentIncome - bracket.first, bracket.second)
                totalTax += taxableAmount
                currentIncome -= taxableAmount
            } else {
                break
            }
        }
    }

    return totalTax
}
/**
 * This function calculates the total tax to be paid based on the given income and tax brackets.
 *
 * @param income The total income of the person.
 * @param taxBrackets A list of pairs representing the tax brackets and corresponding tax rates.
 * @return The total tax amount to be paid.
 */
fun calculateTax(income: Double, taxBrackets: List<Pair<Double, Double>>): Double {
/**
 * This function calculates the total tax to be paid based on the given income and tax brackets.
 *
 * @param income The total income of the person.
 * @param taxBrackets A list of pairs representing the tax brackets and corresponding tax rates.
 * @return The total tax amount to be paid.
 */
fun calculateTax(income: Double, taxBrackets: List<Pair<Double, Double>>): Double {

    var totalTax = 0.0
    var currentIncome = income

    while (currentIncome > 0) {
        for (bracket in taxBrackets) {
            if (currentIncome > bracket.first) {
                val taxableAmount = minOf(currentIncome - bracket.first, bracket.second)
                totalTax += taxableAmount
                currentIncome -= taxableAmount
            } else {
                break
            }
        }
    }

    return totalTax
}