/**
 * Apply discounts to the product prices based on certain conditions.
 *
 * @param products A map of product names as keys and their original prices as values.
 * @param discounts A map of conditions as keys and the corresponding discount percentages as values.
 * @return A new map with product names as keys and their discounted prices as values.
 */
fun applyDiscounts(products: Map<String, Double>, discounts: Map<String, Double>): Map<String, Double> {

    val discountedPrices = mutableMapOf<String, Double>()
    for ((product, price) in products) {
        var discountedPrice = price
        for ((condition, discount) in discounts) {
            when {
                condition == "new_customer" && product.startsWith("N") -> discountedPrice *= (1 - discount)
                condition == "repeat_customer" && product.startsWith("R") -> discountedPrice *= (1 - discount)
                condition == "expensive_item" && price > 100 -> discountedPrice *= (1 - discount)
                condition == "low_stock" && product in listOf("Laptop", "TV") -> discountedPrice *= (1 - discount)
            }
        }
        discountedPrices[product] = discountedPrice.round(2)
    }
    return discountedPrices
}

fun Double.round(decimals: Int): Double = "%.${decimals}f".format(this).toDouble()
/**
 * Apply discounts to the product prices based on certain conditions.
 *
 * @param products A map of product names as keys and their original prices as values.
 * @param discounts A map of conditions as keys and the corresponding discount percentages as values.
 * @return A new map with product names as keys and their discounted prices as values.
 */
fun applyDiscounts(products: Map<String, Double>, discounts: Map<String, Double>): Map<String, Double> {
/**
 * Apply discounts to the product prices based on certain conditions.
 *
 * @param products A map of product names as keys and their original prices as values.
 * @param discounts A map of conditions as keys and the corresponding discount percentages as values.
 * @return A new map with product names as keys and their discounted prices as values.
 */
fun applyDiscounts(products: Map<String, Double>, discounts: Map<String, Double>): Map<String, Double> {

    val discountedPrices = mutableMapOf<String, Double>()
    for ((product, price) in products) {
        var discountedPrice = price
        for ((condition, discount) in discounts) {
            when {
                condition == "new_customer" && product.startsWith("N") -> discountedPrice *= (1 - discount)
                condition == "repeat_customer" && product.startsWith("R") -> discountedPrice *= (1 - discount)
                condition == "expensive_item" && price > 100 -> discountedPrice *= (1 - discount)
                condition == "low_stock" && product in listOf("Laptop", "TV") -> discountedPrice *= (1 - discount)
            }
        }
        discountedPrices[product] = discountedPrice.round(2)
    }
    return discountedPrices
}

fun Double.round(decimals: Int): Double = "%.${decimals}f".format(this).toDouble()