/**
 * This function calculates the number of years it takes for a country's population to reach the target population, based on the given growth rate.
 */
fun populationGrowth(countryName: String, startingPopulation: Double, growthRate: Double, targetPopulation: Double): String {

    var population = startingPopulation
    var years = 0

    while (population < targetPopulation) {
        population *= growthRate
        years++

        if (years > 100) { // If the number of years exceeds 100, break the loop
            break
        }

        if (population > 100000000) { // If the population exceeds 100 million, skip to the next iteration
            continue
        }

        if (countryName == "Economist") {
            when {
                years % 2 == 0 -> population += 500000 // If the number of years is even, add 500000 to the population
                years % 3 == 0 -> population *= 1.5 // If the number of years is divisible by 3, multiply the population by 1.5
                else -> population -= 100000 // For other years, subtract 100000 from the population
            }
        }
    }

    return "It takes $years years for $countryName's population to reach $targetPopulation."
}
/**
 * This function calculates the number of years it takes for a country's population to reach the target population, based on the given growth rate.
 */
fun populationGrowth(countryName: String, startingPopulation: Double, growthRate: Double, targetPopulation: Double): String {
/**
 * This function calculates the number of years it takes for a country's population to reach the target population, based on the given growth rate.
 */
fun populationGrowth(countryName: String, startingPopulation: Double, growthRate: Double, targetPopulation: Double): String {

    var population = startingPopulation
    var years = 0

    while (population < targetPopulation) {
        population *= growthRate
        years++

        if (years > 100) { // If the number of years exceeds 100, break the loop
            break
        }

        if (population > 100000000) { // If the population exceeds 100 million, skip to the next iteration
            continue
        }

        if (countryName == "Economist") {
            when {
                years % 2 == 0 -> population += 500000 // If the number of years is even, add 500000 to the population
                years % 3 == 0 -> population *= 1.5 // If the number of years is divisible by 3, multiply the population by 1.5
                else -> population -= 100000 // For other years, subtract 100000 from the population
            }
        }
    }

    return "It takes $years years for $countryName's population to reach $targetPopulation."
}